#d2952. 程序自动分析
程序自动分析
Program Auto-analysis
Problem Description
When implementing program auto-analysis, we often need to decide whether a set of constraints can be satisfied simultaneously.
Consider a simplified constraint satisfaction problem: let be the variables appearing in a program. You are given constraints of the form or (variable equality / inequality) and must determine whether it is possible to assign a suitable value to every variable so that all the constraints are satisfied at the same time.
For example, if the constraints are , it is clearly impossible to satisfy them all, so the answer should be "not satisfiable".
You are given several such constraint satisfaction problems; determine each of them.
Input Format
The first line of the input contains a positive integer , the number of problems to judge. Note that these problems are independent of one another.
For each problem, the following lines are given:
- The first line contains a positive integer , the number of constraints in this problem.
- The next lines each contain three integers , describing one equality / inequality constraint, with adjacent integers separated by a single space. If the constraint is ; if the constraint is .
Output Format
The output file contains lines.
The -th line of the output contains the string YES or NO. YES means the -th problem in the input is judged to be satisfiable, and NO means it is not.
Sample Input
2
2
1 2 1
1 2 0
2
1 2 1
2 1 1
Sample Output
NO
YES
Constraints
- for each problem,
- ,
- The problems are independent of one another