标签:
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 29940 | Accepted: 9802 |
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
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> #include<vector> #include<stack> using namespace std; int n,m; int fa[1000005],a[1000005]; int find(int x) { if(x!=fa[x]) fa[x]=find(fa[x]); return fa[x]; } void Union(int x,int y) { int fx,fy; fx=find(x),fy=find(y); if(fx!=fy) fa[fx]=fy; } int main() { int tt,x,y,cas=1; scanf("%d",&tt); while(tt--) { bool flag=true; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) fa[i]=i,a[i]=0; for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); int fx,fy; fx=find(x),fy=find(y); if(fx==fy) { flag=false; } if(!a[x]) a[x]=y; else { Union(a[x],y); } if(!a[y]) { a[y]=x; } else { Union(a[y],x); } } printf("Scenario #%d:\n",cas++); if(!flag) printf("Suspicious bugs found!\n\n"); else printf("No suspicious bugs found!\n\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4445999.html