#include <stdio.h>#define MAXV 100010int ans[MAXV],tree[MAXV];int find(int x){ int rt; if(tree[x]!=x){ rt=find(tree[x]); ans[x]=ans[x]^ans[tree[x]];//类别偏移 return tree[x]=rt; } return x;}void TUnion(int x,int y){ int fx,fy; fx=find(x); fy=find(y); tree[fx]=fy; ans[fx]=~(ans[y]^ans[x]);//类别偏移}int main(){ int i,n,m,a,b; char c; int t; scanf("%d",&t); while(t--){ scanf("%d%dn",&n,&m); for(i=0;i<=n;i++){ ans[i]=0; tree[i]=i; } for(i=1;i<=m;i++){ scanf("%c %d %dn",&c,&a,&b); if(c=='D'){ TUnion(a,b); }else{ if(n==2) printf("In different gangs.n"); else if(find(a)==find(b)){ if(ans[a]==ans[b]) printf("In the same gang.n"); else printf("In different gangs.n"); }else printf("Not sure yet.n"); } } } return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)