POJ 2492 A Bug's Life(并查集)
2013-06-17 19:21
477 查看
题目链接
居然没更新flag就交了,错了两次。。3个题,都是一个类型。
居然没更新flag就交了,错了两次。。3个题,都是一个类型。
#include <cstring> #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> using namespace std; int o[5001]; int flag[5001]; int find(int x) { if(x == o[x]) return x; int t = find(o[x]); flag[x] = (flag[x] + flag[o[x]])%2; return o[x] = t; } int main() { int n,m,i,T,cas = 1,x,y,tx,ty,z; scanf("%d",&T); while(cas <= T) { scanf("%d%d",&n,&m); for(i = 1; i <= n; i ++) { o[i] = i; flag[i] = 0; } z = 1; for(i = 0; i < m; i ++) { scanf("%d%d",&x,&y); if(z) { tx = find(x); ty = find(y); if(tx != ty) { o[tx] = ty; flag[tx] = (flag[y] - flag[x] + 3)%2; } else if(tx == ty) { if(flag[x] == flag[y]) z = 0; } } } printf("Scenario #%d:\n",cas++); if(z) printf("No suspicious bugs found!\n"); else printf("Suspicious bugs found!\n"); if(cas <= T) printf("\n"); } return 0; }
相关文章推荐
- 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 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
- 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
- poj 2492 A Bug's Life (并查集)
- POJ---2492 A Bug's Life[并查集]
- poj 2492 A Bug's Life(并查集)
- poj2492_A Bug's Life_并查集
- poj2492——A Bug's Life(并查集扩展)