hdu 1829(并查集)
2017-07-14 20:39
176 查看
题意:两两配偶,其中是一男一女,问会不会出现冲突。
思路:两个并查集,1 ~ n代表男,n + 1 ~ n * 2代表女。
当一个人同时为男或者同时为女的时候冲突产生。
思路:两个并查集,1 ~ n代表男,n + 1 ~ n * 2代表女。
当一个人同时为男或者同时为女的时候冲突产生。
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; const int maxn = 2000 + 10; #define clr(x,y) memset(x,y,sizeof x) int fa[maxn * 2]; int finds(int x) { return fa[x] == x ? x : (fa[x] = finds(fa[x])); } void unions(int x,int y) { int xx = finds(x),yy = finds(y); if(xx != yy) fa[xx] = yy; } int main() { int T; scanf("%d",&T); for(int ii = 1; ii <= T ; ii ++) { bool ans = true; int n,m; scanf("%d%d",&n,&m); for(int i = 1; i <= n * 2;i ++) fa[i] = i; while(m --) { int x,y; scanf("%d%d",&x,&y); unions(x,y + n); unions(x + n,y); } printf("Scenario #%d:\n",ii); for(int i = 1; i <= n; i ++) { if(finds(i) == finds(i + n)) { ans = false; break; } } if(ans) puts("No suspicious bugs found!\n"); else puts("Suspicious bugs found!\n"); } return 0; }
相关文章推荐
- hdu 1829 (并查集)
- hdu 1829 并查集
- HDU 1829 A Bug's Life (分组并查集)
- hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
- hdu 1829 分组并查集
- HDU 1829 并查集
- hdu-1829 & poj-2492 并查集
- HDU_1829 A Bug's Life [ 向量+并查集]
- HDU 1829 A Bug's Life-基础种类并查集
- hdu 1829 &poj 2492 A Bug's Life(推断二分图、带权并查集)
- hdu 1829 A Bug's Life(并查集)
- 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany
- hdu 1829(带权并查集)
- HDU 1829 A Bug's Life(种类并查集)
- HDU-1829 A Bug's Life(并查集)
- hdu 1829 A Bug's Life 并查集系列
- hdu 1829 &poj 2492 A Bug's Life(判断二分图、带权并查集)
- HDU 1829 A Bug's Life 并查集
- HDU-1829 A Bug's Life (带权并查集)
- HDU_1829 A Bug's Life(并查集)