您的位置:首页 > Web前端

hdu1829 A Bug's Life

2015-05-28 22:10 274 查看
#include <cstdio>

#include <cstdlib>

#include <climits>

#include <cstring>

#include <algorithm>

using namespace std;

const int MAX = 2000;

int pre[2*MAX+5];

bool mark;

void init(int n){

int i;

////(author:CSDN:凌风)

for(i=1;i<=MAX+n;++i)pre[i] = i;

mark = true;

}

int root(int x){

if(x!=pre[x]){

pre[x] = root(pre[x]);

}

return pre[x];

}

void merge(int x,int y){

int fx,fy;

fx = root(x);

fy = root(y-MAX);

if(fx==fy){

mark = false;

return;

}

fy = root(y);

if(fx!=fy){

pre[fx] = pre[fy];

}

}

int main(){

//freopen("in.txt","r",stdin);

//(author:CSDN:凌风)

int t,i,n,m,x,y,k;

scanf("%d",&t);

for(i=1;i<=t;++i){

scanf("%d %d",&n,&m);

init(n);

for(k=1;k<=m;++k){

scanf("%d %d",&x,&y);

if(mark){

merge(x,y+MAX);

merge(y,x+MAX);

}

}

printf("Scenario #%d:\n",i);

if(mark){

printf("No suspicious bugs found!\n");

}else{

printf("Suspicious bugs found!\n");

}

printf("\n");

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: