POJ 2492

时间:2023-03-10 01:34:37
POJ 2492
 #include<iostream>
#include<stdio.h>
#define MAXN 2050
using namespace std; int pre[MAXN];
int opp[MAXN]; void init(int n)
{
int i;
for(i = ; i <= n; ++ i)
{
pre[i] = i;
opp[i] = -;
}
} int find_pre(int x)
{
if(pre[x] != x)
{
pre[x] = find_pre(pre[x]);
}
return pre[x];
} int comb(int x,int y)
{
if(x == -)
return y;
if(y == -)
return x;
pre[x] = y;
return y;
} int main()
{
//freopen("acm.acm","r",stdin);
int test;
int n;
int m;
int i;
int u;
int v;
int temp1;
int temp2;
bool boo;
bool bo;
int k;
scanf("%d",&test);
for(k = ; k < test; ++ k)
{
scanf("%d%d",&n,&m);
init(n);
boo = false; cout<<"Scenario #"<<k+<<":"<<endl;
for(i = ; i < m; ++ i)
{
bo = false;
scanf("%d%d",&u,&v);
temp1 = u;
temp2 = v;
if(i != )
{
temp1 = find_pre(temp1);
temp2 = find_pre(temp2);
if(temp1 == temp2)
{
boo = true;
// bo = true;
}
}
if(!boo)
{
u = find_pre(u);
v = find_pre(v);
temp1 = comb(u,opp[v]);
temp2 = comb(opp[u],v);
opp[temp1] = temp2;
opp[temp2] = temp1;
}
}
if(boo)
{
cout<<"Suspicious bugs found!"<<endl;
}
else
{
cout<<"No suspicious bugs found!"<<endl;
}
cout<<endl;
}
}