博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1611 The Suspects
阅读量:6825 次
发布时间:2019-06-26

本文共 2537 字,大约阅读时间需要 8 分钟。

The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 34353   Accepted: 16669

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 42 1 25 10 13 11 12 142 0 12 99 2200 21 55 1 2 3 4 51 00 0

Sample Output

411

Source

 
题目大意:有n个学生,编号为0~n-1,现在编号为0的学生加入了学校的动漫社,感染了污病毒。污病毒具有传染性,一旦社团里有一个人被感染了,其他所有人都会被传染。现在给出每个社团里的学生编号(一个学生可能加入了多个社团),问最后有多少个人被感染。
 
1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 const int mxn=50010; 9 int n,m,ans;10 int fa[mxn];11 int find(int x){12 if(fa[x]==x)return x;13 return fa[x]=find(fa[x]);14 }15 int main(){16 int i,j;17 while(scanf("%d%d",&n,&m) && (n|m)){18 for(i=0;i

 

转载于:https://www.cnblogs.com/SilverNebula/p/5898461.html

你可能感兴趣的文章
硬盘分区时GPT和MBR的区别/选择
查看>>
Nginx 配置简述
查看>>
css后代选择器(div.class中间不带空格)
查看>>
在CentOS下利用Python+selenium获取腾讯首页的今日话题。
查看>>
Chapter 2 Open Book——38
查看>>
word break相关问题的解法
查看>>
java中Scanner的nextLine()和next()的区别
查看>>
Dig
查看>>
21:二维数组右上左下遍历
查看>>
android camera(一):camera模组CMM介绍【转】
查看>>
BZOJ 2821: 作诗(Poetize) [分块]
查看>>
TCP协议三次握手过程分析
查看>>
set排序(个人模版)
查看>>
Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
查看>>
windows进程中的几个杂项-hpguard 进程终止
查看>>
Window 7 + Ubuntu 双系统安装
查看>>
instance 怎么获得自己的 Metadata - 每天5分钟玩转 OpenStack(169)
查看>>
以AVL树为例理解二叉树的旋转(Rotate)操作
查看>>
Maven可以提交到官方公共仓库maven.org
查看>>
学霸也要会看书
查看>>