码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1829 A Bug's Life

时间:2015-05-28 23:15:54      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

hdu1829 A Bug's Life

标签:

原文地址:http://blog.csdn.net/a197p/article/details/46136067

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!