zoj-1789
来源:互联网 发布:如何修改电脑mac地址 编辑:程序博客网 时间:2024/06/05 22:54
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1789
题意:查找与0有关的人 即为SARS 并查集
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int father[30005];int rank[30005] ;int n,m;void init(){ for(int i = 0 ; i < n ;i ++ ) { father[i] = i; rank[i] = 1; //自身节点为1 }}int find(int x){ if(x != father[x]) return find(father[x]); return father[x] ;}void Union(int x,int y){ int xx = find(x); int yy = find(y); if(xx == yy) return ; father[xx] = yy; rank[yy] += rank[xx] ; //记录共同祖先的有多少个成员}int main(){ int a,b,k; while(scanf("%d%d",&n,&m),n+m) { init(); for(int i = 0; i < m ; i++) { scanf("%d%d",&k,&a); for(int j = 1 ; j < k ;j ++) { scanf("%d",&b); Union(a,b); a = b ; } } printf("%d\n",rank[find(0)]);//查找0的祖先 }}
0 0
- zoj 1789
- zoj 1789
- zoj-1789
- ZOJ-1789
- ZOJ 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj - 1789 - The Suspects
- zoj 1789 The Suspects
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- java调用oracle存储过程的自定义类型(可变数组)。
- 用代码给 core data property 设置默认值
- 关于高精度问题的自我总结
- PHP类的静态方法和静态变量
- 手机号码验证,邮箱,车牌验证
- zoj-1789
- 黑马程序员------- IO-------
- Android中在主线程与在子线程中更新UI的探索
- 半年C++学习有感
- Fermat vs. Pythagoras -基础数论(深刻总结)
- linux 的ioctl()函数
- 小强的HTML5移动开发之路(16)——神奇的拖放功能
- JQuery移除一个元素
- 最简单的win32汇编程序