poj 2492 A Bug's Life (并查集)
2014-02-17 20:34
429 查看
题目:http://poj.org/problem?id=2492
题意:跟上一道1703题差不做,
给出m对昆虫交配,问 有没有同性恋。
题意:跟上一道1703题差不做,
给出m对昆虫交配,问 有没有同性恋。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 2010; int bin[maxn], op[maxn], n; void init() { for(int i = 1; i <= n; i++) { bin[i] = i; op[i] = 0; } } int find(int x) { int r, i, j; r = x; while(r != bin[r]) r = bin[r]; i = x; while(bin[i] != r) { j = bin[i]; bin[i] = r; i = j; } return r; } void merge(int x, int y) { int fx, fy; fx = find(x); fy = find(y); if(fx != fy) bin[fx] = fy; } int main() { int t, m, a, b, f, cou=1; scanf("%d", &t); while(t--) { f = 0; scanf("%d%d", &n, &m); init(); while(m--) { scanf("%d%d",&a, &b); if(find(a) == find(b)) f = 1; if(f == 0) { if(op[a] == 0) op[a] = b; else merge(op[a],b); if(op[b] == 0) op[b] =a; else merge(op[b],a); } } printf("Scenario #%d:\n", cou++); if(f) printf("Suspicious bugs found!\n\n"); else printf("No suspicious bugs found!\n\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 并查集的应用
- hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
- 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 (并查集应用的扩展)
- 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[并查集]
- poj2492_A Bug's Life_并查集
- Poj 2492 A Bug's Life(带权并查集)(水)