The Suspects

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

题意: 0号必然感染,和0号一组的是感染者,还有这一组中的去其他人也会去感染其他人,然后问你最多有多少感染者

题解:有一个技巧就是初始化是t[i]=1;在mix()函数中相加。需要注意此题最少有一个人。

#include<stdio.h>
int road[10000000+10];
int t[10000000+10];
int find(int a)
{
if(road[a]==a) return a;
else
return road[a]=find(road[a]);
}
void mix(int a,int b)
{ int x;
int y;
x=find(a);
y=find(b);
if(x!=y)
{
road[y]=x;
t[x]+=t[y];//是两个集合连接在一起,并使人数相加
} }
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
if(n==0&&m==0)
{
break;
}
else
{
int a, b,c,maxx=0;
for(int i=0;i<=n;i++)
{
road[i]=i;
t[i]=1;
}
while(m--)
{ scanf("%d",&a);
scanf("%d",&b);
for(int i=0;i<a-1;i++)
{
scanf("%d",&c);
mix(c,b);
}
}
int MAX=0;
MAX=t[find(0)];
printf("%d\n",MAX);
}
return 0;
}

The Suspects POJ 1611的更多相关文章

  1. (并查集)The Suspects --POJ --1611

    链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  2. C - The Suspects POJ - 1611(并查集)

    Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...

  3. B - The Suspects -poj 1611

    病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ...

  4. 【原创】poj ----- 1611 The Suspects 解题报告

    题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K To ...

  5. poj 1611 The Suspects 解题报告

    题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...

  6. poj 1611 The Suspects(简单并查集)

    题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...

  7. POJ - 1611 The Suspects 【并查集】

    题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...

  8. 【裸的并查集】POJ 1611 The Suspects

    http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...

  9. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

随机推荐

  1. PIO导出

    1..HSSFWorkbook 声明一个工作簿,创建一个excel文件 //创建HSSFWork对象(excel的文档对象) HSSFWorkbook wb=new HSSFWorkbook(); / ...

  2. hibernate课程 初探单表映射2-5 session详解(上)

    1 本章目的:获得session的两种方式: openSession 和 getCurrentSession 2 两种session的使用方法 1openSession可以直接写,getCurrent ...

  3. 前端JS电商放大镜效果

    前端JS电商放大镜效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  4. Windows 10 下使用Git

    事实上,比在Linux下要难很多.不仅仅是因为Linux下CMD功能较弱,还有就是国内的网络环境,至少,我这Github Windows安装时,总是会下载无法完成 Github Desktop 虽然, ...

  5. 【转】【C++】【MFC】各种数据类型大小

    *原文地址:http://blog.csdn.net/xuexiacm/article/details/8122267 /*运行结果分析: 以上结果已经很明白了,一下补充说明几点: 概念.整型:表示整 ...

  6. pg中的非varchar类型的模糊搜索

    模糊搜索,bay字段是 numeric 类型的(如果是 varchar 类型的用常规的即可) 1,SELECT * FROM s_view_monitor_result WHERE bay ~~ CA ...

  7. 解决mysql连接输入密码提示Warning: Using a password on the command line interface can be insecure

    有时候客户端连接mysql需要指定密码时(如用zabbix监控mysql)5.6后数据库会给出个警告信息 mysql -uroot -pxxxx Warning: Using a password o ...

  8. Command Line Client(建库,建表)

    Enter password: ******Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection ...

  9. 64位系统中为VS2012添加OpenGL工具包

    之前一直都是按照网上教程进行的添加,以前使用的系统是32位的,所以一直都没有问题.最近换了64位系统,要使用到OpenGL,于是就又进行了原来的工作,但进行测试时,老是失败: 但是在目录:" ...

  10. 如何从github上拉取项目中的指定目录

    2010开始,对于GitHub上的每一个Git版本库,现在都可以用SVN命令进行操作,而svn命令则是支持部分检出的. 方法如下: 例如我想下载我的nginxinc/kubernetes-ingres ...