poj 2492 A Bug's Life 并查集
2017-04-12 17:43
387 查看
裸的并查集咯
ACcode:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 100010
int myset[maxn];
int find_x(int x){
if(myset[x]==-1)return x;
return myset[x]=find_x(myset[x]);
}
int main(){
int loop,tot=1;
scanf("%d",&loop);
while(loop--){
if(tot>1)printf("\12");
int n,m;
scanf("%d%d",&n,&m);
memset(myset,-1,sizeof(myset));
int flag=0;
while(m--){
int a,b;
scanf("%d%d",&a,&b);
if(find_x(a)!=find_x(b)&&find_x(a)!=find_x(b+n)){
myset[find_x(a)]=find_x(b+n);
myset[find_x(b)]=find_x(a+n);
}
else if(find_x(a)==find_x(b))flag=1;
}
printf("Scenario #%d:\n%s bugs found!\n",tot++,flag==0?"No suspicious":"Suspicious");
}
return 0;
}
/*
*/
ACcode:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 100010
int myset[maxn];
int find_x(int x){
if(myset[x]==-1)return x;
return myset[x]=find_x(myset[x]);
}
int main(){
int loop,tot=1;
scanf("%d",&loop);
while(loop--){
if(tot>1)printf("\12");
int n,m;
scanf("%d%d",&n,&m);
memset(myset,-1,sizeof(myset));
int flag=0;
while(m--){
int a,b;
scanf("%d%d",&a,&b);
if(find_x(a)!=find_x(b)&&find_x(a)!=find_x(b+n)){
myset[find_x(a)]=find_x(b+n);
myset[find_x(b)]=find_x(a+n);
}
else if(find_x(a)==find_x(b))flag=1;
}
printf("Scenario #%d:\n%s bugs found!\n",tot++,flag==0?"No suspicious":"Suspicious");
}
return 0;
}
/*
*/
相关文章推荐
- POJ ~ 2492 ~ A Bug's Life (带权并查集)
- POJ2492 A Bug's Life 【并查集】
- POJ - 2492 -A Bug's Life 【带权并查集讲解】
- poj 2492 A Bug's Life(带权并查集)
- HDU 1829 && POJ 2492 A Bug's Life(种类并查集)
- poj 2492 A Bug's Life(并查集)
- poj 2492 A Bug's Life(带权并查集)
- 【poj 2492】A Bug's Life (带权并查集)
- POJ 2492 A Bug's Life(并查集)
- POJ 2492 A Bug's Life(并查集)
- POJ 2492 A Bug's Life【并查集的简单应用同类的判断】
- POJ 2492-A Bug's Life(带权并查集)
- 【POJ】2492 - A Bug's Life(带权并查集)
- Hdu 1892&&Poj 2492 A Bug's Life[判断二分图 || 种类并查集]
- POJ 2492 A Bug's Life(关系并查集)
- POJ 2492 A Bug's Life(路径压缩并查集)
- Poj 2492 A Bug's Life(带权并查集)(水)
- poj 2492 A Bug's Life(带权并查集)
- POJ 2492 A Bug's Life 带权并查集
- poj 2492 - A Bug's Life(并查集)