The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 19754   Accepted: 9576

Description

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.
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

The input file contains several cases. Each test case begins with two integers n and m in a line, where n is the number of students, and m is the number of groups. You may assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 is recognized as a suspect in all the cases. This line is followed by m member lists of the groups, one line per group. Each line begins with an integer k by itself representing the number of members in the group. Following the number of members, there are k integers representing the students in this group. All the integers in a line are separated by at least one space.
A case with n = 0 and m = 0 indicates the end of the input, and need not be processed.

Output

For each case, output the number of suspects in one line.

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的更多相关文章

  1. poj1611 The Suspects(并查集)

    题目链接 http://poj.org/problem?id=1611 题意 有n个学生,编号0~n-1,m个社团,每个社团有k个学生,如果社团里有1个学生是SARS的疑似患者,则该社团所有人都要被隔 ...

  2. poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)

    http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...

  3. POJ1611 The Suspects (并查集)

    本文出自:http://blog.csdn.net/svitter 题意:0号学生染病,有n个学生,m个小组.和0号学生同组的学生染病,病能够传染. 输入格式:n,m 数量  学生编号1,2,3,4 ...

  4. POJ1611 The Suspects 并查集模板题

    题目大意:中文题不多说了 题目思路:将每一个可能患病的人纳入同一个集合,然后遍历查找每个点,如果改点点的根节点和0号学生的根节点相同,则该点可能是病人. 模板题并没有思路上的困难,只不过在遍历时需要额 ...

  5. poj1611 The suspects【并查集】

    严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not-Spreading-Y ...

  6. POJ1611(The Suspects)--简单并查集

    题目在这里 关于SARS病毒传染的问题.在同一个组的学生是接触很近的,后面也会有新的同学的加入.其中有一位同学感染SARS,那么该组的所有同学得了SARS.要计算出有多少位学生感染SARS了.编号为0 ...

  7. Day 2 下午

    [POJ 3468]A Simple Problem with Integers给定Q个数A1, ..., AQ,多次进行以下操作:1.对区间[L, R]中的每个数都加n.2.求某个区间[L, R]中 ...

  8. poj 1988 Cube Stacking (并查集)

    题意:有N(N<=30,000)堆方块,开始每堆都是一个方块.方块编号1 – N. 有两种操作: M x y : 表示把方块x所在的堆,拿起来叠放到y所在的堆上. C x : 问方块x下面有多少 ...

  9. 暑假集训(2)第二弹 ----- The Suspects(POJ1611)

    B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:20000KB   ...

  10. POJ1611:The Suspects(模板题)

    http://poj.org/problem?id=1611 Description Severe acute respiratory syndrome (SARS), an atypical pne ...

随机推荐

  1. Java:字符串类简单的正则表达式

    class Test { public static void main(String[] args) { String str = "xia..as....yuan.com"; ...

  2. XSS第四节,XSS攻击实例(一)

    在开始实例的讲解之前,先看一下XSS的危害情况,第一张图中说明和XSS相关的CVE漏洞有7417个(http://web.nvd.nist.gov/view/vuln/search-results?q ...

  3. 织梦(Dedecms)V5.6 远程文件删除漏洞

    漏洞版本: DedeCmsV5.6 漏洞描述: DedeCMS内容管理系统软件采用XML名字空间风格核心模板:模板全部使用文件形式保存,对用户设计模板.网站升级转移均提供很大的便利,健壮的模板标签为站 ...

  4. Bootstrap学习js插件篇之滚动监听

    1.滚动监听 案例 滚动监听插件可以根据滚动条的位置自动更新所对应的导航标记.Bootstrap中文网左侧就是一个滚动监听的例子. 代码段: <nav id="navbar-examp ...

  5. 模态框在IE下的问题,即position:fixed在IE下不兼容的处理方式

    项目中遇到的问题,模态框在IE下总出现如图所示双层遮罩框,经排查发现是由于bootstrap里写的modal的样式里position:fixed不兼容IE的原因,导致铺不满整个窗口. 解决方案:在项目 ...

  6. [Javascript] Hositing

    First, memory is set aside for all necessary variables and declared functions. Function expression n ...

  7. 大型开放式网络课程MOOC的一点体会

            2012年,美国的顶尖大学陆续设立网络学习平台,在网上提供免费课程,Coursera.Udacity.edX三大课程提供商的兴起.给很多其它学生提供了系统学习的可能.这就是大型开放式网 ...

  8. ccc数据库的水平分割和垂直分割

    在数据库操作中,我们常常会听说这两个词语:水平分割和垂直分割.那么到底什么是数据库的水平分割,什么是数据库的垂直分割呢?本文我们就来介绍一下这部分内容. 1.水平分割: 按记录进分分割,不同的记录可以 ...

  9. Shell解释器(学习笔记四)

    一.Shell解释器 shell解释器,用户和操作系统内核之间的桥梁 shell介于操作系统内核与用户之间,负责接收用户输入的操作指令(命令),并运行和解释,将需要执行的操作传递给操作系统内核并执行 ...

  10. java面试第十七天

    5.0新特性: 泛型: 泛型的形式: <E> <E extends 类型> <E extends Numner&comparator>  类名&接口 ...