hdu 1829

来源:互联网 发布:mac版office百度云 编辑:程序博客网 时间:2024/04/28 03:02

// Accepted 1829 312MS 260K 1912 B C++
//写程序不是一般的粗心  case次数居然输出了 wrong了十几次
//开两个集合  一个是异性 一个同性

#include<iostream>
#include<cstdio>
using namespace std;
 struct{
    int parent;
    int mate;
}bug[2100];
int deep[2100];
inline void frontset(int n)
{
    int i;
    for (i=0;i<= n;++i)
    {
        bug[i].parent= i;
        bug[i].mate= -1;
        deep[i] = 1;
    }
}
inline int find(int x)
{
    int r,j;
    r = x;
    while(r != bug[r].parent)
    {
        j = r;
        r = bug[r].parent;
        bug[j].parent = bug[r].parent;
    }
    return r;
}
inline void merge(int x,int y)
{
    int fx,fy;
    fx = find(x);
    fy = find(y);
    if(fx != fy)
    {
        if(deep[fx] > deep[fy])
        {
            bug[fy].parent = fx;
        }
        else
        {
            bug[fx].parent = fy;
            if(deep[fx] == deep[fy])
            {
                deep[fy]++;
            }
        }
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    int j=1;
    while (T--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int i;
        frontset(n);
        bool flag=true;
        for (i=0;i<m;++i)
        {
            int a,b;
            scanf("%d%d",&a,&b);
             if (!flag)
             {
                 continue;
             }
            int px,py;
            px=find(a);
            py=find(b);
            if (px==py)
            {
                flag=false;
            }
           if (bug[a].mate!= -1)
            {
                merge(py,bug[a].mate);
            }
            else
            {
                bug[a].mate=py;
            }       
            if (bug[b].mate!= -1)
            {
                merge(px,bug[b].mate);
            }
            else
            {
                bug[b].mate=px;
            }
        }
        printf("Scenario #%d:/n",j);
            j++;
        if (flag)
        {
            puts("No suspicious bugs found!");
        }
        else
        {
            puts("Suspicious bugs found!");
        }
        puts("");
    }
    return 0;
}

 

原创粉丝点击