链接:

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])%2;
    }

    return f[x];
}


int main()
{
    int i, t, n, m, k=1;
    scanf("%d", &t);

    while(t--)
    {
        int a, b, fa, fb, flag=0;
        scanf("%d%d", &n, &m);

        for(i=0; i<=n; i++)
        {
            f[i]=i;
            r[i]=0;
        }


        for(i=0; 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]+1)%2;
            }
            else
            {
                if(r[a]==r[b])
                   flag=1;
            }

        }

        printf("Scenario #%d:\n", k++);
        if(flag)
            printf("Suspicious bugs found!\n\n");
        else
            printf("No suspicious bugs found!\n\n");
    }

    return 0;
}

 

posted on 2015-08-17 10:19  栀蓝  阅读(148)  评论(0编辑  收藏  举报

levels of contents