标签:des style blog color os strong io for
1 #include<iostream> 2 using namespace std; 3 struct Pair 4 { 5 int from,conflict; 6 }; 7 Pair *record; 8 int find(int x) 9 { 10 if(x==record[x].from) 11 return x; 12 return record[x].from=find(record[x].from); 13 } 14 void link(int a,int b) 15 { 16 int fa=find(a); 17 int fb=find(b); 18 if(fa!=fb) 19 record[fb].from=fa; 20 } 21 int main() 22 { 23 int t; 24 int cnt=1; 25 scanf("%d",&t); 26 while(t--) 27 { 28 int n,m; 29 bool flag=false; 30 scanf("%d %d",&n,&m); 31 record=new Pair[n+1]; 32 for(int i=1;i<=n;i++) 33 { 34 record[i].from=i; 35 record[i].conflict=0; 36 } 37 int a,b; 38 for(int i=1;i<=m;i++) 39 { 40 scanf("%d %d",&a,&b); 41 int fa=find(a); 42 int fb=find(b); 43 if(fa==fb)flag=true; 44 if(record[a].conflict!=0) 45 { 46 link(b,record[a].conflict); 47 } 48 if(record[b].conflict!=0) 49 { 50 link(a,record[b].conflict); 51 } 52 record[a].conflict=b; 53 record[b].conflict=a; 54 } 55 cout<<"Scenario #"<<cnt<<":\n"; 56 if(flag)cout<<"Suspicious bugs found!\n"; 57 else cout<<"No suspicious bugs found!\n"; 58 cout<<endl; 59 cnt++; 60 } 61 return 0; 62 }
标签:des style blog color os strong io for
原文地址:http://www.cnblogs.com/sytu/p/3872234.html