标签:art txt from queue root blank class rip arch
2 3 3 1 2 2 3 1 3 4 2 1 2 3 4Sample Output
Scenario #1: Suspicious bugs found! Scenario #2: No suspicious bugs found!
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<queue> 7 #include<map> 8 #include<set> 9 #include<vector> 10 #include<cstdlib> 11 #include<string> 12 #define eps 0.000000001 13 typedef long long ll; 14 typedef unsigned long long LL; 15 using namespace std; 16 const int N=2000+100; 17 int flag[N]; 18 int parent[N]; 19 int m,n; 20 void init(){ 21 for(int i=0;i<=n;i++)parent[i]=i; 22 memset(flag,0,sizeof(flag)); 23 } 24 int find(int x){ 25 if(parent[x]!=x){ 26 int root=parent[x]; 27 parent[x]=find(parent[x]); 28 flag[x]=(flag[x]+flag[root])%2; 29 } 30 return parent[x]; 31 } 32 /* 33 int find(int x){ 34 int r=x; 35 while(r!=parent[r])r=parent[r]; 36 int i=x; 37 int j; 38 while(i!=r){ 39 flag[i]=(flag[i]+flag[parent[i]])%2; 40 j=parent[i]; 41 parent[i]=r; 42 i=j; 43 } 44 return r; 45 }*/ 46 void Union(int x,int y){ 47 int xx=find(x); 48 int yy=find(y); 49 parent[xx]=yy; 50 flag[xx]=(flag[y]+flag[x]+1)%2; 51 } 52 int main() 53 { 54 //freopen("text.txt","r",stdin); 55 int T,kase; 56 scanf("%d",&T); 57 for(int kase=1;kase<=T;kase++) 58 { 59 scanf("%d%d",&n,&m); 60 init(); 61 int flag1=0; 62 for(int i=0;i<m;i++) 63 { 64 int x,y; 65 scanf("%d%d",&x,&y); 66 if(flag1) 67 continue; 68 int fx=find(x); 69 int fy=find(y); 70 if(fx==fy) 71 { 72 if(flag[x]==flag[y]) 73 flag1=1; 74 } 75 else 76 Union(x,y); 77 } 78 printf("Scenario #%d:\n",kase); 79 if(flag1) 80 printf("Suspicious bugs found!\n"); 81 else 82 printf("No suspicious bugs found!\n"); 83 if(kase!=T) 84 printf("\n"); 85 } 86 return 0; 87 }
标签:art txt from queue root blank class rip arch
原文地址:http://www.cnblogs.com/Aa1039510121/p/6476650.html