1611 The Suspects 并查集
来源:互联网 发布:淘宝店铺整体运营思路 编辑:程序博客网 时间:2024/05/17 15:41
Description Input Output Sample Input Sample Output Source
In the Not-Spreading-Your-Sickness University (NSYSU), there are many student groups. Students in the same group intercommunicate with each other frequently, and a student may join several groups. To prevent the possible transmissions of SARS, the NSYSU collects the member lists of all student groups, and makes the following rule in their standard operation procedure (SOP).
Once a member in a group is a suspect, all members in the group are suspects.
However, they find that it is not easy to identify all the suspects when a student is recognized as a suspect. Your job is to write a program which finds all the suspects.
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.100 42 1 25 10 13 11 12 142 0 12 99 2200 21 55 1 2 3 4 51 00 0
411
#include<stdio.h>
int n,m,k;
int father[30010],num[30010];
int getfather(int x)
{
if(x!=father[x]) father[x]=getfather(father[x]);
return father[x];
}
void Union(int a,int b)
{
a=getfather(a);
b=getfather(b);
if(a==b)
return;
if(num[a]<num[b])
{
father[a]=b;
num[b]+=num[a];
}
else
{
father[b]=a;
num[a]+=num[b];
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0) break;
for(int i=0;i<n;i++)
{
father[i]=i;
num[i]=1;
}
while(m--)
{
int x;
scanf("%d",&k);
scanf("%d",&x);
for(int i=2;i<=k;i++)
{
int y;
scanf("%d",&y);
Union(x,y);
}
}
printf("%d/n",num[getfather(0)]);
}
return 0;
}
- 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 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 并查集
- 烧开一壶水的智慧
- PMD规则之Junit Rules
- Linux加载模块命令
- 外部网如何访问公司内部网的WEB站点
- Foursquare和Gowalla的运营模式
- 1611 The Suspects 并查集
- 可代替Windows自带记事本的软件
- 【Box 2D物理引擎C++】Box 2D环境配置
- Linux内核模块概述
- 面向对象设计原则
- LPC ARM使用SPI总线控制8个LED灯实例。
- 将Notepad2替换Windows的Notepad(针对WindowsXP)
- delphi触发datetimepicker的onchange事件
- 向往是一种距离