很爽快的是这次题目一遍看懂~~好几个前些天刚记的生词~~...这道题和POJ-1073类似...解题思路也相似...用一个数组father来指向各个集合的标志头..用一个数组a来指向每个集合的异性集合...做的时候注意好随时随时合并集合就好了...1A~~~
Program:
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
int T,t,n,m,i,father[2005],a[2005],x,y;
bool f;
int getfather(int x)
{
if (father[x]==x) return x;
return father[x]=getfather(father[x]);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&T);
for (t=1;t<=T;t++)
{
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
{
father[i]=i;
a[i]=0;
}
f=true;
while (m--)
{
scanf("%d%d",&x,&y);
if (!f) continue;
x=getfather(x); y=getfather(y);
if (x==y) { f=false; continue; }
if (!a[x]) a[x]=y;
if (!a[y]) a[y]=x;
a[y]=getfather(a[y]);
a[x]=getfather(a[x]);
father[a[x]]=y;
father[a[y]]=x;
}
printf("Scenario #%d:\n",t);
if (f) printf("No suspicious bugs found!\n");
else printf("Suspicious bugs found!\n");
if (t!=T) printf("\n");
}
return 0;
}