#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int f[N*2],a[N],b[N],c[N],n,t,p[N*2],cnt;
int find(int x)
{
if(x!=f[x])f[x]=find(f[x]);
return f[x];
}
int main()
{
cin>>t;
while(t--)
{
int flag=1;
cin>>n;
cnt=0;
for(int i=1;i<=2*n;i++)f[i]=i;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
p[++cnt]=a[i];p[++cnt]=b[i];
}
sort(p+1,p+cnt+1);
cnt=unique(p+1,p+cnt+1)-(p+1);
for(int i=1;i<=n;i++)
if(c[i]){
int x=lower_bound(p+1,p+cnt+1,a[i])-p;
int y=lower_bound(p+1,p+cnt+1,b[i])-p;
int fx=find(x),fy=find(y);
if(fx==fy)continue;
f[fx]=fy;
}
for(int i=1;i<=n;i++)
if(!c[i])
{
int x=lower_bound(p+1,p+cnt+1,a[i])-p;
int y=lower_bound(p+1,p+cnt+1,b[i])-p;
int fx=find(x),fy=find(y);
if(fx==fy)flag=0;
}
if(flag)puts("YES");
else puts("NO");
}
return 0;
}

最新文章

  1. 免费道路 bzoj 3624
  2. UOJ79 一般图最大匹配
  3. Android开发之详解五大布局
  4. Win10系统80端口被pid=4的System进程占用 -- 解决方法
  5. Mysql有两种存储引擎:InnoDB与Myisam
  6. Ubuntu 设置su密码
  7. 0125 多线程 继承Thread 练习
  8. RGBa颜色 css3的Alpha通道支持
  9. DOM this, currentTarget, Target
  10. linux sar查看网络流量
  11. 利用PHP SOAP扩展实现简单Web Services
  12. Django中的枚举类型
  13. Python Scrapy反爬虫常见解决方案(包含5种方法)
  14. 【Python 15】分形树绘制3.0(递归函数)
  15. CentOS7.3上如何安装Apache/2.4.34
  16. 盐城 - 开设IT公司的好地方
  17. 基于jquery 的dateRangePicker 和 My97DatePicker
  18. centos 6.5 上安装使用upsource
  19. FastReport.Net使用:[2]添加MSSQL数据源一
  20. EventStore .NET API Client在使用线程池线程同步写入Event导致EventStore连接中断的问题研究

热门文章

  1. Linux 核心系统命令目录
  2. 11.15 dmidecode:查询系统硬件信息
  3. Linux Access.conf安全配置
  4. RSA算法在Python Django中的简单应用
  5. Winsock2使用记录
  6. JRebel插件使用详解(IDEA热部署)(Day_44)
  7. 死磕nginx系列
  8. Configuration注解
  9. CVPR2020论文解读:OCR场景文本识别
  10. eclipse左边的工程列表窗口不见了解决方案