The number of points is very large, can not be saved, but fewer points, so the use of discretization, and then use and check set.
Discretization with map, over 8 points, 2 timeouts
Code:
#include <iostream>#include<cstring>#include<algorithm>#include<map>#defineSize 1000005*2using namespaceStd;map<int,int>dic;structin{intX,y,e;} Data[size];intf[size*2];inten[size][2]; intCnt=0;intNBOOLFlag;intPa[size];voidinit () { for(intI=1; i<size;i++) pa[i]=i; memset (EN,0,sizeof(en));}intFindintx) { if(X!=pa[x]) pa[x]=find (pa[x]); returnpa[x];}BOOLQueryintXinty) { returnFind (x) = =find (y);}voidUnintXinty) { if(Query (x, y))return; Pa[find (x)]=find (y); }intMain () {intT;cin>>T; while(t--) {flag=true; Cnt=0; Init (); CIN>>N; for(intI=1; i<=n;i++) {cin>>data[i].x>>data[i].y>>DATA[I].E; f[2*i-1]=data[i].x; f[2*i]=data[i].y; } sort (F+1, f+1+n*2); for(intI=1; i<=n*2; i++){ if(f[i]!=f[i-1]) {CNT++; Dic[f[i]]=CNT; } } intE,x,y; intnum=0; for(intI=1; i<=n;i++) {x=dic[data[i].x]; Y=DIC[DATA[I].Y]; E=DATA[I].E; if(e==1) un (x, y); Else{num++; en[num][0]=x; en[num][1]=y; } } for(intI=1; i<=num;i++) {x=en[i][0]; y=en[i][1]; if(query (x, y)) {flag=false; Break; } } if(flag) cout<<"YES"<<Endl; Elsecout<<"NO"<<Endl; }}
Codevs 4600 [NOI2015] program automatic analysis