View Code
#include<stdio.h>
#define N 2009
int e[N];
int f[N];
int find(int pos)
{
if(f[pos]==-1)return pos;
return f[pos]=find(f[pos]);
}
int un(int a,int b)
{
int fa=find(a),fb=find(b);
if(fa==fb)return 0;
f[fa]=fb;return 1;
}
int main()
{
int t,n,m,rt,a,b,ca=0,i,T;
scanf("%d",&T);
t=T;
while(t--)
{
ca++;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
f[i]=-1;
e[i]=-1;
}
rt=0;
for(i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
if(find(a)==find(b))
rt=1;//判断即可
int fa,fb;
fa=find(a);
fb=find(b);
if(e[fa]==-1)
{
e[fa]=fb;
}
else
{
un(e[fa],fb);
}
if(e[fb]==-1)
{
e[fb]=fa;
}
else
{
un(e[fb],fa);
}
}
if(rt==1)
{
printf("Scenario #%d:\n",ca);
printf("Suspicious bugs found!\n");
}
else
{
printf("Scenario #%d:\n",ca);
printf("No suspicious bugs found!\n");
}
if(ca!=T)
printf("\n");
}
}