diu· @ 2018-11-05 07:40:59
#include<iostream>
#include<cstdio>
#define MAXN 12000
using namespace std;
int n,m,x,y,z;
int f[MAXN];
int find(int x){return f[x]==x?x:find(f[x]);}
int main()
{
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++)f[i]=i;
for(int i = 1;i <= m;i++)
{
scanf("%d%d%d",&z,&x,&y);
int t1=find(x);
int t2=find(y);
if(z==1){if(t1!=t2)f[t2]=t1;}
else
{
if(t1!=t2)printf("N\n");
else printf("Y\n");
}
}
return 0;
}
int find(int x)
{
int y = x;
while(y!=f[y])y = f[y];
while(x!=f[x])
{
int pr = f[x];
f[pr] = y;x = pr;
}
return x;}
就过了... 问问大佬这是为什么?(萌新看不懂qwq,不都是找爸爸操作嘛)
by diu· @ 2018-11-05 08:14:02
@sdxjzsq 谢谢dalaoヽ( ̄▽ ̄)ノ