Automated Program Analyzer

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Let x_1,x_2,x_3,x\_1, x\_2, x\_3, \dots be variables. nn constraints of form x_i=x_jx\_i = x\_j or x_ix_jx\_i \ne x\_j 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 x_1=x_2,x_2=x_3,x_3=x_4,x_1x_4x\_1 = x\_2, x\_2 = x\_3, x\_3 = x\_4, x\_1 \ne x\_4, then those constraints cannot be satisfied simultaneously.

입력

The first line of the input is an integer tt representing the number of instances to solve. The instances are independent. For each instance, the first line is an integer nn representing the number of constraints to be satisfied. In the following nn lines, each line has three integers i,j,ei,j,e representing an equality/inequality constraint. If e=1e = 1, the constraint shall be x_i=x_jx\_i = x\_j. If e=0e = 0, the constraint shall be x_ix_jx\_i \ne x\_j.

출력

The output has tt lines. The kk-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.

제한

  • 1n100,0001 \le n \le 100\\,000
  • 1i,j1,000,000,0001 \le i, j \le 1\\,000\\,000\\,000
  • 1t101 \le t \le 10
  • e0,1e \in \\{0,1\\}