I have an n-formula.
For each formula, it is either the form of the XI = XJ or the form of the XI <> XJ.
Now I'm going to give you these n formulas, and you tell me if it's possible that these n formulas will be set up at the same time.
"Input Format"
Each test point has multiple sets of test data.
The first group has an integer T, which represents the number of groups of test data.
For each set of group test data, the first row contains a positive integer n, which represents the number of the equation.
The next n lines, three integers per line, i,j,e, describing n formulas. If E = 1, then this equation
For Xi = XJ. If E = 0, then this type? is XI? = XJ.
"Output Format"
For each set of test data outputs. If there is a scheme that makes all the equations be satisfied,
Output "YES" (without quotation marks). Otherwise the output "no" (without quotation marks).
Sample Input 1
2
2
121
120
2
121
211
Sample Output 1
NO
YES
6
Sample Input 2
2
3
121
231
311
4
121
231
341
140
Sample Output 2
YES
NO
"Data Range"
For 20% of data, n≤10.
For 40% of data, n≤100.
For 70% of data, N≤105,1≤i, j≤104.
For 100% of data, N≤105,1≤i, j≤109,1≤t≤10.
"Problem-solving ideas"
This is a comparison of water noi of the topic, mainly and check the application of the set, first sort, put the equation in one and check the concentration, and then to check the inequalities, if there is not satisfied, then output ' no ', all meet the output ' YES '.
Simple and check set can get 90 points, after discretization can get full marks (obviously, I will not write)
1 typeeqq=Record2 L,r:longint;3 End;4 var5EQ,NEQ:Array[0..100000] ofeqq;6Ro:Array[0..100000] ofLongint;7 Sum,sum1,sum2,d,b,c,i,j,flag,t,n,w,max:longint;8 functionRoot (X:longint): Longint;9 beginTen ifX=RO[X] Thenexit (x); Oneroot:=root (Ro[x]); Aro[x]:=Root; - exit (root); - End; the - procedureUnion (X,y:longint); - begin -Ro[root (x)]:=root (y); + End; - + begin AAssign (input,'prog.in'); Reset (input); atAssign (output,'Prog.ans'); Rewrite (output); - read (t); - forw:=1 toT Do - begin -sum1:=0; sum2:=0; sum:=0; flag:=0; max:=0; - read (n); in fori:=1 toN Do - begin to read (d,b,c); + ifD>max Thenmax:=D; - ifB>max Thenmax:=b; the ifC=1 Then * begin $ Inc (SUM1);Panax Notoginsengeq[sum1].l:=D; -eq[sum1].r:=b; the End; + ifC<>1 Then A begin the Inc (SUM2); +neq[sum2].l:=D; -neq[sum2].r:=b; $ End; $ End; - fori:=1 toMax Doro[i]:=i; - fori:=1 toSum1 Do the ifRoot (EQ[I].L) <>root (EQ[I].R) ThenUnion (EQ[I].L,EQ[I].R); - fori:=1 toSum2 DoWuyi begin the ifRoot (NEQ[I].L) <>root (NEQ[I].R) ThenContinue - Else Wu begin -flag:=1; About Break ; $ End; - End; - ifflag=1 ThenWriteln ('NO')ElseWriteln ('YES'); - End; A close (input); close (output); + End.
NOI T1 equation