```c
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
typedef pair<int,int>PII;
vector<PII> eqs,uneqs;
unordered_map<int,int> H;
const int N=1000010;
int p[N],cnt=1;
int map(int x){
if(H.count(x))return H[x];
else H[x]=cnt++;
}
int find(int x){
if(p[x]==x)return x;
return p[x]=find(p[x]);
}
int T,n;
int main(){
cin>>T;
while(T--){
cin>>n;
cnt=0;
H.clear();
eqs.clear();
uneqs.clear();
for(int i=1;i<=n;i++){
int e,x,y;
cin>>x>>y>>e;
x=map(x);
y=map(y);
if(e)eqs.push_back({x,y});
else uneqs.push_back({x,y});
}
for(int i=0;i<=cnt;i++)p[i]=i;
for(auto item:eqs){
p[find(item.first)]=find(item.second);
}
int flag=1;
for(auto item:uneqs){
if(find(item.first)==find(item.second)){
flag=0;
break;
}
}
if(flag==1)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
```
by YOU法克 @ 2019-01-31 11:39:15
@[YOU法克](/space/show?uid=104745) 去看评测及环境,垃圾蒟蒻
by countryhope_lzc @ 2019-01-31 11:43:31
@[2480027228lzc](/space/show?uid=104738) %%%!!!
by Kuriyama_Mirai @ 2019-01-31 11:46:48
@[Harry__James__Potter](/space/show?uid=92066) 这个%啥意思,(我和楼主认识,我不是在嘲讽他)
by countryhope_lzc @ 2019-01-31 11:52:08
@[2480027228lzc](/space/show?uid=104738) 额,你可能不是$C/C++$党?在$C/C++$里,$\huge\%$是取模运算,也就是$\bold{\text{取}\,\huge{\text{膜}}}$ $\bold{\text{运算}}$
by Kuriyama_Mirai @ 2019-01-31 11:56:38
@[Harry__James__Potter](/space/show?uid=92066) 我懂膜的,我只是解释我不是很巨,并且没有嘲讽楼主(我是老实人)。
by countryhope_lzc @ 2019-01-31 11:58:03