poj 1611
来源:互联网 发布:tcp多线程网络编程 编辑:程序博客网 时间:2024/05/16 12:31
http://poj.org/problem?id=1611
题意:0为传染源,和0在同一集合内的都认定为患者
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int father[30005],a[30005],rank[50005];int Find(int x){while(x!=father[x])x=father[x];return x;}int main(){int n,m,i,k,x,y;while(scanf("%d%d",&n,&m)&&n||m){for(i=0;i<=n;i++){father[i]=i;rank[i]=1;}while(m--){scanf("%d",&k);for(i=0;i<k;i++)scanf("%d",&a[i]);for(i=1;i<k;i++){x=Find(a[0]);y=Find(a[i]);if(x!=y){father[y]=x;rank[x]+=rank[y];}}}printf("%d\n",rank[Find(0)]);//居然因为rank[father[0]]错了好久,哎}return 0;}
- POJ 1611
- POJ 1611
- poj 1611
- poj-1611
- poj 1611
- poj 1611
- poj 1611
- POJ 1611
- poj 1611
- POJ 1611
- poj--1611
- poj 1611
- poj-1611
- poj 1611
- poj-1611
- poj 1611
- poj 1611
- poj 1611
- C语言const修饰符探秘
- php知识盲点
- 最大子段和问题,最大子矩阵和问题,最大m子段和问题
- Oracle 11G在RHEL 5.3上的安装文档
- D-separation 2013/4/21 0:59
- poj 1611
- 黑马程序员----JAVA基础集合框架_迭代器
- 16周规划17周总结
- cygwin中的环境变量设置
- Oracle11g RAC for Linux 实施手册
- hdu 1150
- 软RAID-mdadm 折腾小记
- Linux下Oracle_11G_r2_(64位)安装教程
- 雅安 挺住