链接:
http://poj.org/problem?id=2492
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/J
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std; #define N 10005 int f[N], r[N]; int Find(int x)
{
int k=f[x];
if(x!=f[x])
{
f[x]=Find(f[x]);
r[x]=(r[x]+r[k])%;
} return f[x];
} int main()
{
int i, t, n, m, k=;
scanf("%d", &t); while(t--)
{
int a, b, fa, fb, flag=;
scanf("%d%d", &n, &m); for(i=; i<=n; i++)
{
f[i]=i;
r[i]=;
} for(i=; i<m; i++)
{
scanf("%d%d", &a, &b);
fa=Find(a);
fb=Find(b);
if(fa!=fb)
{
f[fa]=fb;
r[fa]=(r[b]-r[a]+)%;
}
else
{
if(r[a]==r[b])
flag=;
} } printf("Scenario #%d:\n", k++);
if(flag)
printf("Suspicious bugs found!\n\n");
else
printf("No suspicious bugs found!\n\n");
} return ;
}