POJ 2492 A Bug's Life
2014-04-11 14:06
323 查看
这题跟 POJ 1703 Find them and Catch them 是一样一样的,就不讲解了,不懂可以看
http://www.cnblogs.com/whatbeg/p/3498416.html
代码:
View Code
http://www.cnblogs.com/whatbeg/p/3498416.html
代码:
#include <iostream> #include <cstdio> using namespace std; #define N 2100 int fa ,sa ; void makeset(int n) { for(int i=1;i<=n;i++) { fa[i] = i; sa[i] = 0; // 0 : same 1 : different } } int findset(int x) { if(x != fa[x]) { int tmp = fa[x]; fa[x] = findset(fa[x]); sa[x] = (sa[tmp] + sa[x]) % 2; } return fa[x]; } void unionset(int a,int b) { int x = findset(a); int y = findset(b); if(x == y) return; fa[x] = y; sa[x] = (sa[a] + sa[b] + 1)%2; return; } int main() { int t,n,m,i; int a,b; int cs = 1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); makeset(n); int flag = 1; for(i=1;i<=m;i++) { scanf("%d%d",&a,&b); if(findset(a) == findset(b)) { if(sa[a] == sa[b]) { flag = 0; } } else unionset(a,b); } printf("Scenario #%d:\n",cs++); if(flag) cout<<"No suspicious bugs found!"<<endl; else cout<<"Suspicious bugs found!"<<endl; cout<<endl; } return 0; }
View Code
相关文章推荐
- 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
- POJ2492 A Bug's Life
- poj 2492 A Bug's Life
- poj-2492- A Bug's Life
- 【带偏移量的并查集】:poj2492,A Bug's Life
- poj 并查集 - 2492 A Bug's Life
- poj 2492 并查集 A Bug's Life
- poj 2492 并查集 a bug's life
- poj2492_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 1829 &poj 2492 A Bug's Life(推断二分图、带权并查集)