NOI '15 P1 - Automated Program Analyzer

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem types

Let x1,x2,x3, be variables. n constraints of form xi=xj or xixj are given. The task asks for whether it is possible to assign values to the variables so that all constraints can be satisfied. For example, if the constraints are x1=x2,x2=x3,x3=x4,x1x4, then those constraints cannot be satisfied simultaneously.

Input Specification

The first line of the input is an integer t representing the number of instances to solve. The instances are independent. For each instance, the first line is an integer n representing the number of constraints to be satisfied. In the following n lines, each line has three integers i,j,e representing an equality/inequality constraint. If e=1, the constraint shall be xi=xj. If e=0, the constraint shall be xixj.

Output Specification

The output has t lines. The k-th line of the output is a string YES or NO. Output YES if the constraints in that instance can be satisfied and NO otherwise.

Sample Input 1

Copy
2
2
1 2 1
1 2 0
2
1 2 1
2 1 1

Sample Output 1

Copy
NO
YES

Sample Input 2

Copy
2
3
1 2 1
2 3 1
3 1 1
4
1 2 1
2 3 1
3 4 1
1 4 0

Sample Output 2

Copy
YES
NO

Constraints

Test Caseni,jAdditional Constraints
11n101i,j100001t10
e{0,1}
2
31n100
4
51n100000
6
7
81n1000001i,j1000000000
9
10

Comments

There are no comments at the moment.