#include<cstdio>
const int N=1e4+10;
int n,m,fa[N];
inline int Find(int x){return x==fa[x]?x:fa[x]=Find(fa[x]);}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
fa[i]=i;
for(int i=1;i<=m;i++)
{
int z,x,y;
scanf("%d%d%d",&z,&x,&y);
if(z==1)fa[Find(x)]=Find(y);
else puts(Find(x)==Find(y)?"Y":"N");
}
return 0;
}
【模板】并查集
最新推荐文章于 2024-07-29 20:58:50 发布