Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位仁兄指点指点wa了好久了 , 都检查不出来!!!!!!!!!!#include <stdio.h> int father[100010], kind[100010]; void makeset(int n) { int i; for(i=1;i<=n;++i) { father[i]=i; kind[i]=0; } } int findset(int x) { if(x!=father[x]) { father[x]=findset(father[x]); kind[x]=(kind[x]+kind[father[x]])%2; } return father[x]; } void Union(int x, int y) { int xx, yy; xx=findset(x); yy=findset(y); if(xx==yy) return ; else { father[yy]=xx; kind[yy]=(kind[x]+kind[y]+1)%2; } } int main() { int T, N , M, ai, bi, aai, bbi; char strc; scanf("%d", &T); while(T--) { scanf("%d%d", &N, &M); makeset(N); while(M--) { scanf("\n%c%d%d",&strc ,&ai, &bi); if(strc=='D') { Union(ai, bi); } else { aai=findset(ai); bbi=findset(bi); if(aai!=bbi) { printf("Not sure yet.\n"); } else if(aai==bbi) { if(kind[bi]==kind[ai]) { printf("In the same gang.\n"); } else { printf("In different gangs.\n"); } } } } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator