POJ 1611 The Suspects (并查集)
来源:互联网 发布:雀神作弊软件 编辑:程序博客网 时间:2024/04/30 08:35
题目链接:http://poj.org/problem?id=1611
函数:void Empty()、int Find(int x)、void Union(int r1,int r2) 这三个函数,要背熟。
# include <iostream>using namespace std;int n, m, i, j;int father[30005], num[30005];void makeSet(int n){ for(i = 0; i < n; i++) {father[i] = i; //使用本身做根num[i] = 1; }}int findSet(int x){ if(father[x] != x) //合并后的树的根是不变的 { father[x] = findSet(father[x]); } return father[x];}void Union(int a, int b){ int x = findSet(a); int y = findSet(b); if(x == y) {return; } if(num[x] <= num[y]) { father[x] = y; num[y] += num[x]; } else { father[y] = x; num[x] += num[y]; }}int main(){ while(scanf("%d %d", &n, &m)!=EOF && n != 0) { makeSet(n); for(i = 0; i < m; i++) { int count, first, b; scanf("%d %d",&count, &first); for(j = 1; j < count; j++) { scanf("%d",&b); Union(first,b); } } printf("%d\n",num[findSet(0)]); } return 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(并查集)
- Android小项目之八 界面细节
- memcpy()与strcpy()的完全实现
- 基于”啪啪奇”产品体验谈视频网站移动端发展
- hdu4460(BFS)
- C++ 11 标准
- POJ 1611 The Suspects (并查集)
- vc工程中各种文件的作用
- 浅析SteinerTree(斯坦纳树)
- 国内外软件服务外包平台
- linux-ubuntu下gdb调试技巧
- QT 信号与槽 QT简单加法器的实现
- 理想的营销状态:战略策略战术三位一体
- hibernate中自动创建表的配置
- 直接拿来用!超实用的Java数组技巧攻略