这题数据好水啊(
查看原帖
这题数据好水啊(
126763
Vector_楼主2020/11/17 22:15

RT

看到范围懒得离散化,就把输入全部%1e6+1

然后50pts->100pts??

我直接迷惑2333

code:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read(){ll x;scanf("%lld",&x);return x;}
int u[1000010],v[1000010],l[1000010],r[1000010],cnt=0;
int f[1000010];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
void un(int x,int y){f[find(y)]=find(x);}
int main()
{
	int t=read();
	while(t--)
	{
		int n=read();
		memset(u,0,sizeof(u));
		memset(v,0,sizeof(v));
		cnt=0;
		for(int i=1;i<=1000000;i++) f[i]=i;
		for(int i=1;i<=n;i++)
		{
			int a=read()%1000000+1,b=read()%1000000+1,op=read();
			if(op==1) un(a,b);
			else u[++cnt]=a,v[cnt]=b;
		}
		bool ok=true;
		for(int i=1;i<=cnt;i++)
			if(find(u[i])==find(v[i]))
			{
				ok=false;
				break;
			}
		if(ok) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
2020/11/17 22:15
加载中...