poj 1611 The Suspects(并查集)
来源:互联网 发布:黄金软件哪个好 编辑:程序博客网 时间:2024/05/21 17:14
#include <cstdio>int f[30010];int n,m;int getf(int x){ if(x == f[x]) return x; return (f[x] = getf(f[x]));}void merge(int a, int b){ a = getf(a); b = getf(b); if(a != b) { if(b == 0) f[a] = b; else if(a == 0) f[b] = a; else f[b] = a; }}int main(){ int a,b,k,res; while(scanf("%d %d",&n,&m) && n) { res = 0; for(int i = 0; i < n; ++i) f[i] = i; for(int i = 0; i < m; ++i) { scanf("%d %d",&k,&a); for(int j = 1; j < k; ++j) { scanf("%d",&b); merge(a,b); } } //本来以为这样会超时呢,没想到才16M for(int i = 0; i < n; ++i) if(getf(i) == 0) ++res; printf("%d\n",res); } 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 1611The 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(并查集)
- 文章标题
- 在CentOS最小化服务器版本中如何查找网卡IP和其它详细信息?
- java 验证码
- MYSQL相关
- poj 1265 Area
- poj 1611 The Suspects(并查集)
- 网络爬虫爬取小说3
- map的4中遍历方式
- TF-IDF权重计算:TfidfTransformer(),CountVectorizer()和TfidfVectorizer()
- Python 面试题 https://github.com/taizilongxu/interview_python
- 应用集成实战系列:集成应用的业务日志很重要
- java集合细节(二):asList的缺陷
- Shiro的使用与配置实战
- 傅里叶变换