hdu1829 A Bug's Life
来源:互联网 发布:手机怎么进去淘宝秒杀 编辑:程序博客网 时间:2024/06/06 07:30
#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;
}
#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;
}
0 0
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- HDU1829- A Bug's Life
- hdu1829 a bug's life
- HDU1829 POJ2492 A Bug's Life
- HDU1829 A Bug's Life 并查集
- HDU1829(A Bug's Life )—并查集
- A Bug's Life hdu1829 并查集
- A Bug's Life(hdu1829种类并查集)
- hdu1829 A Bug's Life (并查集)
- hdu1829 A Bug's Life 并查集
- hdu1829 A Bug's Life(并查集)
- HDU1829 - A Bug's Life 分组并查集
- hdu1829 A Bug's Life --分组并查集
- HDU1829:A Bug's Life(并查集)
- HDU1829:A Bug's Life(种类并查集)
- 郁闷的 linux error: 13: Permission denied 引发Linux中的文件权限详解
- iOS - 中三种定时器的用法NSTimer、CADisplayLink、GCD
- 算法入门2(c语言)
- 题目1368:二叉树中和为某一值的路径
- 微信公众平台开发入门教程
- hdu1829 A Bug's Life
- 不要在init和dealloc函数中使用accessor(访问器)
- linux fping命令使用
- Oracle PLSQL 学习笔记摘要
- HDU 2050 折线分割平面
- uva 129
- SQL Inner Join
- palindrome partition II
- [LeetCode] Reorder List