아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Automated Program Analyzer

면접 대비

시간 제한2초메모리 제한1024 MB

요약
여러 변수에 대한 등식과 부등식 제약을 동시에 만족시킬 수 있는지 판정한다.
난이도

보통10점 중 5점

유형
유니온 파인드, 그래프
정답자
아직 제출이 없습니다

문제

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_i≠x_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_1≠x_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_i≠x_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.

제한

  • 1≤n≤100,0001 \le n \le 100\\,000
  • 1≤i,j≤1,000,000,0001 \le i, j \le 1\\,000\\,000\\,000
  • 1≤t≤101 \le t \le 10
  • e∈0,1e \in \\{0,1\\}

예제2

  1. 예제 1

    입력
    2
    2
    1 2 1
    1 2 0
    2
    1 2 1
    2 1 1
    
    예상 출력
    NO
    YES
    
  2. 예제 2

    입력
    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