A Bug’s Life |
---|
题意: 在m对关系中,不同性别可以在一起,要求判断是否有同性在一起的情况
#include<iostream>
#include<algorithm>
using namespace std;
#define _for(i, a, b) for(int i = (a); i <= (b); ++i)
const int N = 2e3 + 10;
int _T, tot, n, m;
int s[N << 1];
int find(int x) { return s[x] == x ? x : s[x] = find(s[x]);}
void un(int a, int b) {
a = find(a), b = find(b);
s[a] = b;
}
int main() {
scanf("%d", &_T);
while(_T--) {
int flag = 1;
scanf("%d%d", &n, &m);
_for(i, 1, n << 1) s[i] = i;
while(m--) {
int a, b;
scanf("%d%d", &a, &b);
if(flag) {
if(find(a) == find(b) || find(a + n) == find(b + n)) flag = 0;
else {
un(a, b + n);
un(a + n, b);
}
}
}
printf("Scenario #%d:\n", ++tot);
printf("%s\n\n", flag ? "No suspicious bugs found!" : "Suspicious bugs found!");
}
return 0;
}