poj union_find相关之1611 The Suspects
2017-06-20 19:38
281 查看
poj union-find 1611 The Suspects
就是简单的并查集
252K 16MS
比较高端的并查集的题 1182:食物链可以参考如下的博客:
http://blog.163.com/happyliyifan@126/blog/static/37462772201361695127793/
http://blog.csdn.net/tiantangrenjian/article/details/7085575
就是简单的并查集
#include<cstdio> #include<cstring> #include<iostream> #include<memory.h> #define MAXS 30005 #define MAXG 505 using namespace std; int n, m; int pre[MAXS]; int find(int t) { int a = t; while (pre[a] != a) a = pre[a]; return a; } void union_int(int a,int b) { int x, y; x = find(a); y = find(b); if (x != y) pre[y] = x; } int main() { //freopen("1.txt", "r", stdin); int i, j, k, a, b, cont; while (scanf("%d%d", &n, &m) != EOF && (n || m)) { for (i = 0; i < n; i++) pre[i] = i; for (i = 0; i < m; i++) { scanf("%d", &k); scanf("%d", &a); for (j = 1; j < k; j++) { scanf("%d", &b); union_int(a, b); } } cont = 1; j = find(0); for (i = 1; i < n;i++) if (find(i) == j) cont++; printf("%d\n", cont); } }
252K 16MS
比较高端的并查集的题 1182:食物链可以参考如下的博客:
http://blog.163.com/happyliyifan@126/blog/static/37462772201361695127793/
http://blog.csdn.net/tiantangrenjian/article/details/7085575
相关文章推荐
- kuangbin_UnionFind B (POJ 1611)
- poj 1611 The Suspects
- POJ 1611 The Suspects
- POJ1611:The Suspects
- POJ 1611 The Suspects
- poj 1611 the suspects
- zoj 1789 || poj 1611 The Suspects(并查集)
- poj 1611-The Suspects:并查集
- POJ 1611 The Suspects
- poj 1611 The Suspects
- POJ 1611 The Suspects(并查集)
- poj 1611 The Suspects (并查集)
- POJ 1611 The Suspects (并查集)
- zoj 1789||poj 1611 The Suspects(并查集,简单)
- poj 1611 The Suspects 初级->数据结构->简单并查集的应用
- POJ 1611 The Suspects
- POJ 1611 The Suspects(并查集)
- Poj 1611 The Suspects
- POJ 1611 The Suspects (并查集)
- poj 1611-The Suspects:并查集