标签:www. span find put class cst init com ace
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=10010; int fa[maxn],n,m; void init(){ for(int i=1;i<=n;i++)fa[i]=i; } int find(int x){ if(fa[x]==x)return x; return fa[x]=find(fa[x]); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y)return; fa[x]=y; } int main() { scanf("%d%d",&n,&m); init();int x,y,z; for(int i=1;i<=m;i++){ scanf("%d%d%d",&z,&x,&y); if(z==1)unite(x,y); else{if(find(x)==find(y))puts("Y");else puts("N");} } return 0; }
本文由Yzyet编写,网址为www.cnblogs.com/Yzyet。非Yzyet同意,禁止转载,侵权者必究。
标签:www. span find put class cst init com ace
原文地址:http://www.cnblogs.com/Yzyet/p/7257535.html