标签:
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 31006 | Accepted: 10159 |
Description
Input
Output
Sample Input
2 3 3 1 2 2 3 1 3 4 2 1 2 3 4
Sample Output
Scenario #1: Suspicious bugs found! Scenario #2: No suspicious bugs found!
Hint
Source
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=2000+5; int p[MAXN],w[MAXN]; int kase,n,m; bool flag; void init() { memset(p,-1,sizeof(p)); memset(w,0,sizeof(w)); flag=false; } int findfa(int x) { if(p[x]==-1) return x; int tmp=p[x]; p[x]=findfa(p[x]); w[x]=(w[x]+w[tmp])%2; return p[x]; } int main() { //freopen("in.txt","r",stdin); int Case=0; scanf("%d",&kase); while(kase--) { scanf("%d %d",&n,&m); init(); for(int i=0;i<m;i++) { int u,v; scanf("%d %d",&u,&v); int x=findfa(u); int y=findfa(v); if(flag) continue; if(x==y) { if(w[u]==w[v]) flag=true; } else { p[y]=x; w[y]=(1-w[u]-w[v]+2)%2; } } printf("Scenario #%d:\n",++Case); if(flag) printf("Suspicious bugs found!\n\n"); else printf("No suspicious bugs found!\n\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/clliff/p/4699897.html