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

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

The Suspects
Time Limit: 1000MS   Memory Limit: 20000K
Total Submissions: 26945   Accepted: 13165

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

 
题意:(非典爆发, 传染 && 学生分小组&&编号为零学生被怀疑(与编号0学生同组的都被怀疑,和被怀疑学生为一组的都被怀疑))→ → 典型的并查集, 求0所在集合中元素的个数。
1 #include 
2 #include
3 using namespace std; 4 int father[30030], num[30030]; 5 int i, n; 6 7 void init() 8 { 9 for(i=0; i

 

 
 

转载于:https://www.cnblogs.com/soTired/p/4697116.html

你可能感兴趣的文章
面试必考题!你知道CSS实现水平垂直居中的第10种方式吗?
查看>>
超多惊喜!苹果 iPhone8 最新渲染图曝光
查看>>
你想要不想要?OPPO R11将搭配前后2000万像素镜头!
查看>>
Payara基金会发布全面支持MicroProfile 2.0的5.183版
查看>>
360金融宣布采用新会计准则 2018年前三季度净利11亿
查看>>
非洲小哥见到马云 竟然提了这样的要求?
查看>>
收购大战:高通承诺将年收入增长率提至8%
查看>>
宁夏:科技创新激活高质量发展动能
查看>>
毕马威:中国消费未现降级 进一步增长潜力巨大
查看>>
四川眉山:苏东坡诞辰982周年非遗传承人展技艺
查看>>
新式茶饮市场扩张 网红奶茶店如何解决排队难题?
查看>>
兰州百万现金表彰星级的哥的姐 弘扬敬业奉献美德
查看>>
Python比总统更受关注:关于Python的五个事实
查看>>
第二代NumPy?阿里开源超大规模矩阵计算框架Mars
查看>>
几小时的事儿,苹果刚发布iOS 11.2.1又被阿里安全工程师完美越狱
查看>>
react配置eslint
查看>>
Web 安全漏洞之 OS 命令注入
查看>>
大数据平台架构技术选型与场景运用
查看>>
每天一个设计模式之享元模式
查看>>
微服务调用链追踪中心搭建
查看>>