#P3634. Identifying Hidden Ninjas

    ID: 16885 Type: Default 1000ms 256MiB

Identifying Hidden Ninjas

Identifying Hidden Ninjas

APIO Kingdom is under attack by ninjas! These ninjas are very powerful because they can hide in the shadows making them invisible to others. The entire kingdom except the APIO Castle is occupied. In front of the castle there are NN bushes numbered from 11 to NN. Exactly KK ninjas are hiding behind exactly KK bushes. Inside the castle, there are MM guards. Guard ii monitors a contiguous range of bushes from AiA_i to BiB_i. Each guard reports whether or not there is at least one ninja in his range. In particular, if the report is 1 then there is at least one ninja in the range, and if the report is 0 then there is no ninja among those bushes. Under the constraint that the positions of ninjas (i.e. the set S{1,2,,N}S\subseteq \{1,2,\dots,N\} with S=K|S|=K) must be consistent with every guard's report, your task is to determine all bushes that definitely hide a ninja, i.e. bushes jj such that in every ninja arrangement consistent with the guard reports, bush jj contains a ninja.

More formally, let xix_i be 1 if bush ii hides a ninja and 0 otherwise. You are given that [ \sum_{i=1}^{N}x_i=K,] and for each guard with report rr monitoring bushes from AA to BB, it holds that [ \text{if } r=1, ; \sum_{i=A}^{B} x_i \ge 1 \quad \text{and} \quad \text{if } r=0, ; \sum_{i=A}^{B} x_i = 0.] A bush jj is guaranteed to have a ninja if in every solution (assignment) satisfying these conditions, we have xj=1x_j=1.

Your program should output all such bush numbers in increasing order (separated by spaces).

inputFormat

The first line contains three integers NN, KK, and MM. Each of the following MM lines contains three integers AiA_i, BiB_i, and rir_i, where AiA_i and BiB_i (1AiBiN1 \le A_i \le B_i \le N) denote the range that guard ii monitors and rir_i is either 0 or 1 representing the guard’s report.

outputFormat

Output the bush numbers that are guaranteed to hide a ninja in increasing order, separated by a space. If no bush is guaranteed, output an empty line.

sample

5 2 3
1 3 1
2 5 1
3 4 0

</p>