poj1611---The Suspects
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 19754 | Accepted: 9576 |
Description
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.
Input
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.
Output
Sample Input
100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
200 2
1 5
5 1 2 3 4 5
1 0
0 0
Sample Output
4
1
1
Source
#include<stdio.h>
#include<string.h>
#define maxn 30000
int n,m;
int father[maxn],rank[maxn];
void init()
{
for(int i=;i<n;i++)
{
father[i]=i;
rank[i]=;
}
}
int setfind(int x)
{
if(x!=father[x])
x=setfind(father[x]);
return x; }
void _union(int a,int b)
{
a=setfind(a);
b=setfind(b);
if(a!=b)
{
if(rank[a]<rank[b])
{
father[a]=b;
rank[b]+=rank[a];
}
else
{
father[b]=a;
rank[a]+=rank[b];
}
}
}
int main()
{
int a,b,c;
while(scanf("%d%d",&n,&m),m+n)
{
init();
while(m--)
{
scanf("%d %d",&a,&b);
while(a>)
{
scanf("%d",&c);
_union(b,c);
b=c;
a--;
}
}
printf("%d\n",rank[setfind()]);
} return ;
}
poj1611---The Suspects的更多相关文章
- poj1611 The Suspects(并查集)
题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- POJ1611 The Suspects (并查集)
本文出自:http://blog.csdn.net/svitter 题意:0号学生染病,有n个学生,m个小组.和0号学生同组的学生染病,病能够传染. 输入格式:n,m 数量 学生编号1,2,3,4 ...
- POJ1611 The Suspects 并查集模板题
题目大意:中文题不多说了 题目思路:将每一个可能患病的人纳入同一个集合,然后遍历查找每个点,如果改点点的根节点和0号学生的根节点相同,则该点可能是病人. 模板题并没有思路上的困难,只不过在遍历时需要额 ...
- poj1611 The suspects【并查集】
严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not-Spreading-Y ...
- POJ1611(The Suspects)--简单并查集
题目在这里 关于SARS病毒传染的问题.在同一个组的学生是接触很近的,后面也会有新的同学的加入.其中有一位同学感染SARS,那么该组的所有同学得了SARS.要计算出有多少位学生感染SARS了.编号为0 ...
- Day 2 下午
[POJ 3468]A Simple Problem with Integers给定Q个数A1, ..., AQ,多次进行以下操作:1.对区间[L, R]中的每个数都加n.2.求某个区间[L, R]中 ...
- poj 1988 Cube Stacking (并查集)
题意:有N(N<=30,000)堆方块,开始每堆都是一个方块.方块编号1 – N. 有两种操作: M x y : 表示把方块x所在的堆,拿起来叠放到y所在的堆上. C x : 问方块x下面有多少 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- POJ1611:The Suspects(模板题)
http://poj.org/problem?id=1611 Description Severe acute respiratory syndrome (SARS), an atypical pne ...
随机推荐
- tomcat配置301重定向
tomcat默认情况下不带www的域名是不会跳转到带www的域名的,而且也无法像apache那样通过配置.htaccess来实现.如果想要把不带“www'的域名重定向到带”www"域名下,又 ...
- 在JSP中应用JavaBean
1. 解决中文乱码的JavaBean 在JSP页面中,处理中文字符经常会出现字符乱码的现象,特别是通过表单传递中文数据时容易产生.它的解决办法有很多,如将request的字符集指定为中文字符集,编写J ...
- data-stream-as-disjoint-intervals
https://leetcode.com/problems/data-stream-as-disjoint-intervals/ /** * Definition for an interval. * ...
- Informatica 常用组件Lookup之八 查找高速缓存
可以配置查找转换以高速缓存查找文件或表.PowerCenter 将在处理高速缓存查找转换中的第一个数据行时在存储器中建立高速缓存.它将根据您在转换或会话特性中配置的数量来分配高速缓存区内存.Power ...
- Visual Studio 调试方法
1:命令窗口 CTRL + D + I,可以在立即窗口中写一些临时的代码 2:编辑并继续 选中下面的选项,可以让你在调试暂停中,修改代码,而不用重新启动, 3:执行 单步执行:F10 跳进方法:F11 ...
- go语言知识点
1.make()只是用3种内建的引用类型:切片.map和channel.new函数分配内存,make函数初始化. 2.:=只能使用在函数内部.
- Ubuntu下安装Hadoop
终于把Hadoop的环境给配好了.在美国的第一个周末,非常的折腾,电脑坏了,一开机windows动画过后屏幕就没显示,无语死了,在想着人生地不熟的,哪里去找人修电脑,还好一个舍友说看到隔壁街有个PC ...
- Logistic Regression的几个变种
原文:http://blog.xlvector.net/2014-02/different-logistic-regression/ 最近几年广告系统成为很多公司的重要系统之一,定向广告技术是广告系统 ...
- 避免闪烁的方法(OnEraseBkgnd)
在图形图象处理编程过程中,双缓冲是一种主要的技术.我们知道,假设窗口在响应WM_PAINT消息的时候要进行复杂的图形处理,那么窗口在重绘时因为过频的刷新而引起闪烁现象. 解决这一问题的有效方法就是双缓 ...
- 在 Win 7 下使用 VirtualBOX 虚拟机安装 OS X 10.9 Mavericks 及 Xcode 5
参考网址:http://bbs.feng.com/read-htm-tid-7625465.html