/*并查集*/
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 2005;
int father[MAXN], Rank[MAXN];
int cas = 0, t;
int n, m;
bool flag;
void init()
{
for (int i = 0; i < n; ++i) {
father[i] = i;
Rank[i] = 0;
}
return;
}
int getfather(int x)
{
if (x == father[x]) return x;
int tmp;
tmp = getfather(father[x]);
Rank[x] = (Rank[x] + Rank[father[x]]) % 2;
father[x] = tmp;
return father[x];
}
void merge(int x, int y)
{
int fx, fy;
fx = getfather(x);
fy = getfather(y);
if (fx == fy) {
if (Rank[x] == Rank[y]) flag = false;
}
else {
father[fx] = fy;
Rank[fx] = (Rank[x] + Rank[y] + 1) % 2;
}
return;
}
int main()
{
cin >> t;
while (t--) {
cin >> n >> m;
init();
flag = true;
int x, y;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
if (!flag) continue;
merge(x, y);
}
cout << "Scenario #" << ++cas << ":" << endl;
if (flag) cout << "No suspicious bugs found!" << endl << endl;
else cout << "Suspicious bugs found!" << endl << endl;
}
return 0;
}
POJ2492 A Bug's Life
最新推荐文章于 2020-08-16 23:22:25 发布