POJ 1611 The Suspects
来源:互联网 发布:如何用sql语句创建表 编辑:程序博客网 时间:2024/05/16 06:19
题目链接:http://poj.org/problem?id=1611
详细题解:裸的并查集 把每一个group排一个序, 最小的为根,当然,如果其中的某个节点的根最小,那么这个这个节点的根就为这个group的根,这样就可以把所有与0有关系的节点归纳到一起啦啦啦…… 水吧0.0
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#define N 31000int F[N];int num[N];int fun(int x){ if(F[x] != x) F[x] = fun(F[x]); return F[x];}int main (){ int n, m; while(scanf("%d %d", &n, &m) != EOF) { if(n == 0 && m == 0) break; if(m == 0) {puts("1"); continue;} for(int i = 0; i <= n; i++) F[i] = i; for(int i = 1; i <= m; i++) { int no; scanf("%d", &no); for(int j = 1; j <= no; j++) scanf("%d", &num[j]); sort(num+1, num+1+no); int fa = fun(num[1]); for(int j = 2; j <= no; j++) { int fb = fun(num[j]); if(fa > fb) swap(fa, fb); F[fb] = fa; } } for(int i = 1; i <= n; i++) F[i] = fun(i); int ans = 0; for(int i = 0; i <= n; i++) if(F[i] == 0) ans++; printf("%d\n", ans); } return 0;}
0 0
- 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
- 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
- POJ 1611 The Suspects
- POJ 1611 The Suspects
- poj 1611 the suspects
- POJ 1611 The Suspects
- UVA 11255 Necklace(Polya)
- C# 使用反射动态加载子窗体
- java 关于字节流和字符流的区别
- (code jam)Problem A. Magic Trick
- 《编写高质量代码》读书笔记
- POJ 1611 The Suspects
- 【2048强势来袭】第六期:添加游戏是否还能够继续的模块
- Java—内部类
- slony I 数据复制工具的安装与应用
- 安全联盟认证登陆QQ浏览器,中网认证被取代
- oracle删除(释放)数据文件/表空间流程
- decreases inversion count
- 第七周项目6人数不定的工资类
- python第三方库系列之二十四--http-web库