| ||||||||||
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至死,。。。。。。。。。。。已经死了,菜鸟求助。用一个二维数组edge记录连线,从小的点指向大的点。然后再对数组进行操作,一组和0合并,一组和2001合并。并判断是否有gay,用一个result数组记录每组数据的结果。 #include<iostream> #define MAXSIZE 2002 using namespace std; int parent[MAXSIZE]; int countofset; int result[1000],count; int edge[MAXSIZE][MAXSIZE]; void clear() { for(int x=0;x!=MAXSIZE;++x) for(int y=0;y!=MAXSIZE;++y) edge[x][y]=0; parent[0]=0; for(int i=0;i!=MAXSIZE;++i) parent[i]=i; } int findset(int x) { if(x!=parent[x]) parent[x]=findset(parent[x]); return parent[x]; } void unionset(int root1,int root2) { int x=findset(root1); int y=findset(root2); if(x==y) return ; parent[root1]=root2; } int main() { count=0; int N=0; cin>>N; int i=0; result[0]=0; for(i=0;i!=N;++i) { clear(); int numberofbugs,iter,x,y; cin>>numberofbugs>>iter; countofset=numberofbugs; bool flag=true; for(int j=0;j!=iter;++j) { cin>>x>>y; if(x!=y) { if(x<y) edge[x][y]=1; else edge[y][x]=1; } } for(x=1;x<=numberofbugs;++x) { int sets=findset(x); int oppsets; if(sets!=0 && sets!=2001) { unionset(x,0); oppsets=2001; sets=0; } else if(sets==0) oppsets=2001; else if(sets==2001) oppsets=0; for(int y=1;y<=numberofbugs;++y) { if(edge[x][y]) { if(findset(y)==sets) flag=false; else unionset(y,oppsets); } } } if(flag) result[count++]=1; else result[count++]=0; } cout<<endl; for(i=0;i!=N;++i) if(result[i]) { cout<<"Scenario #"<<i+1<<":"<<endl; cout<<"No suspicious bugs found!"<<endl; cout<<endl; } else { cout<<"Scenario #"<<i+1<<":"<<endl; cout<<"Suspicious bugs found!"<<endl; cout<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator