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<algorithm> #include<iostream> #include<cmath> #include<cstdio> #define MAXN 100005 using namespace std; int root[MAXN]; int relation[MAXN]; int find(int n) { int t; if(root[n]==n) return n; else t=find(root[n]); root[n]=t; relation[n]=(relation[n]+relation[root[n]])%2; return t; } void inti(int n) { for(int i=0; i<n; i++) { root[i]=i; relation[i]=0; } } void uni(int a,int b) { int ra=find(a); int rb =find(b); if(ra==rb) return; root[b]=a; relation[b]=(relation[a]-relation[b]+3)%2; } int main() { int n,m,k,a,b; char operat; while(cin>>k) { while(k--) { cin>>m>>n; inti(m); for(int i=0; i<n; i++) { cin>>operat; scanf("%d%d",&a,&b); if(m==2) { printf("In different gangs.\n"); continue; } if(operat=='A') { if(find(a)!=find(b)) printf("Not sure yet.\n"); else { if((relation[a]-relation[b]+2)%2==0) printf("In the same gang.\n"); else printf("In different gangs.\n"); } } else uni(a,b); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator