#P1955. [NOI2015] 程序自动分析
[NOI2015] 程序自动分析
Description
During the implementation of automatic program analysis, it is often necessary to determine whether certain constraints can be satisfied simultaneously.
Consider a simplified version of a constraint satisfaction problem: suppose represent variables that appear in the program. Given constraints of the form or , determine whether it is possible to assign an appropriate value to each variable so that all the constraints are satisfied simultaneously. For example, if the constraints in one problem are , these constraints are clearly impossible to satisfy at the same time, so this problem should be judged as unsatisfiable.
Now you are given several constraint satisfaction problems. Please determine each of them.
Input Format
The first line contains a positive integer , indicating the number of problems to judge. Note that these problems are independent of each other.
For each problem, there are several lines:
The first line contains a positive integer , indicating the number of constraints that need to be satisfied in this problem. The next lines each contain three integers , describing one equality/inequality constraint, with a single space between adjacent integers. If , then the constraint is . If , then the constraint is .
Output Format
Output lines.
On the -th line, output the string YES or NO (all uppercase). YES means the -th problem in the input is judged satisfiable, and NO means it is unsatisfiable.
2
2
1 2 1
1 2 0
2
1 2 1
2 1 1
NO
YES
2
3
1 2 1
2 3 1
3 1 1
4
1 2 1
2 3 1
3 4 1
1 4 0
YES
NO
Hint
[Sample Explanation 1]
In the first problem, the constraints are . These two constraints contradict each other, so they cannot be satisfied simultaneously.
In the second problem, the constraints are . These two constraints are equivalent and can be satisfied simultaneously.
[Sample Explanation 2]
In the first problem, there are three constraints: . It suffices to assign values so that , and all constraints are satisfied.
In the second problem, there are four constraints: . From the first three constraints we can derive , but the last constraint requires , so it is unsatisfiable.
[Constraints]
All testdata ranges and characteristics are as follows:
::cute-table{tuack} | Test point id | Range of | Range of | Conventions | | :-: | :-: | :-: | :-: | | | | | ; | | | ^ | ^ | ^ | | | | ^ | ^ | | | ^ | ^ | ^ | | | | ^ | ^ | | | ^ | ^ | ^ | | | ^ | ^ | ^ | | | | | ^ | | | ^ | ^ | ^ | | | ^ | ^ | ^ |
Translated by ChatGPT 5
京公网安备 11011102002149号