标签:pre 并查集 amp find logs union scan log void
传送门:亲戚
1 #include<cstdio> 2 3 const int MAXN = 10001; 4 5 int Father[MAXN],n,m; 6 char Check[3]={‘N‘,‘Y‘}; 7 8 int Find(int t) 9 { 10 if(t!=Father[t]) return Father[t]=Find(Father[t]); 11 return Father[t]; 12 } 13 14 void Union(int u,int v) 15 { 16 u=Find(u); 17 v=Find(v); 18 Father[u]=v; 19 } 20 21 int main() 22 { 23 scanf("%d%d",&n,&m); 24 for(int i=1;i<=n;i++) 25 Father[i]=i; 26 for(int i=1,Job,u,v;i<=m;i++) 27 { 28 scanf("%d%d%d",&Job,&u,&v); 29 if(Job==2) 30 { 31 u=Find(u); 32 v=Find(v); 33 printf("%c\n",Check[u==v]); 34 } 35 else 36 Union(u,v); 37 } 38 return 0; 39 }
标签:pre 并查集 amp find logs union scan log void
原文地址:http://www.cnblogs.com/Never-See/p/6387027.html