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