eolymp
bolt
Try our new interface for solving problems

Guard

The Kingdom of APIO is attacked by ninjas. Ninjas are very strong because, when they attack, they are hiding in the shadows and other people cannot see them. The Kingdom was captured except for the APIO castle, where the king lives. In front of the APIO castle, there is a line of \textbf{N} bushes. The bushes are numbered from \textbf{1} to \textbf{N}, and \textbf{K} ninjas are hiding in exactly \textbf{K} bushes. There are \textbf{M} guards in the APIO castle. The guard \textbf{i} is watching a sequence of bushes from the bush \textbf{A_i} to the bush \textbf{B_i}. Now, each guard reports to the king whether there is a ninja in the bushes he/she is watching. Since you are a servant of the king, you have to tell him, based on the reports from the guards, in which bush "a ninja is certainly hiding". Here, "a ninja is certainly hiding" in a bush if a ninja is hiding in it for any possible arrangement of ninjas which does not contradict the reports from the guards. \textbf{Task} Write a program that, given information of the guards and the reports from them, determines all bushes where "a ninja is certainly hiding". \textbf{Constraints} \textbf{1} ≤ \textbf{N} ≤ \textbf{100000} - The number of bushes \textbf{1} ≤ \textbf{K} ≤ \textbf{N} - The number of hidden ninjas \textbf{1} ≤ \textbf{M} ≤ \textbf{100000} - The number of guards \InputFile The first line contains three space separated integers \textbf{N}, \textbf{K}, \textbf{M}, where \textbf{N} is the number of bushes, \textbf{K} is the number of hidden ninjas, and \textbf{M} is the number of guards. The following \textbf{M} lines contain the information of the guards and the reports from them. The \textbf{i}-th line of them contains three space separated integers \textbf{A_i}, \textbf{B_i}, \textbf{C_i} (\textbf{A_i} ≤ \textbf{B_i}), describing that the guard \textbf{i} is watching from the bush \textbf{A_i} to the bush \textbf{B_i}. The integer \textbf{C_i} is either \textbf{0} or \textbf{1}. If \textbf{C_i = 0}, there is no ninja from the bush \textbf{A_i} to the bush \textbf{B_i}. If \textbf{C_i = 1}, there is at least one ninja from the bush \textbf{A_i} to the bush \textbf{B_i}. For each input, it is guaranteed that there is at least one arrangement of ninjas which does not contradict the reports from the guards. \OutputFile If there is a bush where "a ninja is certainly hiding", output the numbers of the bushes where "a ninja is certainly hiding" to the standard output. The numbers of bushes should be written in ascending order, and one line of output should contain only one number. Therefore, if there are \textbf{X} bushes where "a ninja is certainly hiding", the output consists of \textbf{X} lines. If there is no bush where "a ninja is certainly hiding", output '\textbf{-1}' to the standard output. \textbf{Note Sample} In example \textbf{1}, there are two possible arrangements of ninjas satisfying the conditions; three ninjas are hiding in the bush \textbf{1}, \textbf{3}, \textbf{5}, or three ninjas are hiding in the bush \textbf{2}, \textbf{3}, \textbf{5}. Since a ninja is hiding in the bush \textbf{3} and \textbf{5} for any possible arrangements, we should output \textbf{3} and \textbf{5}. Concerning the bush \textbf{1}, there is a possible arrangement of ninjas where a ninja is hiding in the bush \textbf{1}. But there is also a possible arrangement of ninjas where no ninja is hiding in the bush \textbf{1}. Therefore, we should not output \textbf{1}. By the same reason, we should not output \textbf{2}. In example \textbf{2}, there is no bush where "a ninja is certainly hiding". Therefore, we should output '\textbf{-1}'.
Time limit 1 second
Memory limit 256 MiB
Input example #1
5 3 4
1 2 1
3 4 1
4 4 0
4 5 1
Output example #1
3
5
Source 2012 Asia-Pacific Informatics Olympiad (APIO), Problem B