hdu-1829 & poj-2492 并查集
2015-01-19 11:00
483 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1829
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <set> #include <map> #include <iomanip> using namespace std; int t, n, m; int fa[2200]; int sex[2200];//sex[i]=j 表示i与j性别相反 int a, b; int ok; int findd(int x) { if (x == fa[x]) return x; else return findd(fa[x]); } void un(int x, int y) { int fx = findd(x); int fy = findd(y); if (fx == fy)//同性的 { return; } else { if (fy > fx) fa[fy] = fx; else fa[fx] = fy; } } int cases = 1; int main() { scanf("%d",&t); while (t--) { ok = 1; scanf("%d %d", &n, &m); { for (int i = 1; i <= n; i++) { fa[i] = i; } memset(sex,0,sizeof(sex)); for (int i = 1; i <= m;i++) { scanf("%d%d",&a,&b); if (!ok) continue; if (findd(a) == findd(b))//同性的 { ok = 0; continue; } if (sex[a] == 0) { sex[a] = b; } else { un(sex[a], b); } if (sex[b] == 0) { sex[b] = a; } else { un(sex[b], a); } } } if (!ok) { printf("Scenario #%d:\n",cases++); puts("Suspicious bugs found!"); printf("\n"); } else { printf("Scenario #%d:\n",cases++); puts("No suspicious bugs found!"); printf("\n"); } } return 0; }
相关文章推荐
- HDU 1829 & POJ 2492 A Bug's Life (并查集)
- HDU 1829 && POJ 2492 A Bug's Life(种类并查集)
- hdu 1829 &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 || HDU 1829:A Bug's Life(并查集)
- hdu 1829 &poj 2492 A Bug's Life(判断二分图、带权并查集)
- hdu 1829 Poj 2492 A Bug's Life
- POJ 2492/hdu 1829 A Bug's Life【带权并查集】
- Hdu 1892&&Poj 2492 A Bug's Life[判断二分图 || 种类并查集]
- Hdu 1829 A Bug's Life && Poj 1182 食物链 (并查集偏移量的应用)
- [并查集]HDU 1829/POJ 2492/HOJ 2319 A Bug's Life
- 类似区间计数的种类并查集两题--HDU 3038 &amp; POJ 1733
- 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 3038 & POJ 1733
- poj 2492 A Bug's Life(带权并查集)
- HDU 1325&&POJ 1308 Is It A Tree? 并查集判断能否树(能否形成环)