1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <iostream> #include <string.h> using namespace std; const int maxn = 2e4; int n,m; int a,b; int pre[maxn]; int rala[maxn]; void init(int k) { memset(rala,0,sizeof rala); for (int i=1; i<=k; i++) pre[i] = i; } int find(int x) { int temp = pre[x]; if (x==pre[x]) return x; pre[x] = find(temp); rala[x] = rala[x]^rala[temp]; return pre[x]; } void merge(int a,int b) { int ra = find(a); int rb = find(b); if (ra == rb) return; pre[ra] = rb; rala[ra] = (rala[a] + rala[b] +1)%2; } int cnt; int main() {
int scenery ; scanf("%d",&scenery); while (scenery--) { scanf("%d%d",&n,&m); init(n); bool flag = true; for (int i=1; i<=m; i++) { scanf("%d%d",&a,&b); int ra = find(a); int rb = find(b); if (ra == rb) { if (rala[a]^rala[b] != 1) flag = false; } else { merge(a,b); } } if (flag) printf("Scenario #%d:\nNo suspicious bugs found!\n",++cnt); else { printf("Scenario #%d:\nSuspicious bugs found!\n",++cnt); } if (scenery != 0) printf("\n"); } return 0; }
|