当前位置:网站首页>POJ1611_ The Suspects
POJ1611_ The Suspects
2022-07-27 12:28:00 【51CTO】
The Suspects
Time Limit: 1000MS | | Memory Limit: 20000K |
Total Submissions: 22366 | | Accepted: 10875 |
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
The main idea of the topic :
n Students belong to m Groups ,(0 < n <= 30000 , 0 <= m <= 500) A student can belong to multiple groups . A student is suspected to be ill , Then the whole group it belongs to is suspected to be sick . It is known that 0 Student No. 1 is suspected to be ill , And which students make up each group , Ask how many students are suspected to be ill .
Ideas : The most basic application of union search set . Put all suspicious things together . among , Use a total Array ,total[find(a)] yes a Where
Number of people gathered . The final output 0 The total number of infections in the set of node , That is to say 0 The total number of infections in the root node of node .
Code :
边栏推荐
- 上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质
- Openpyxl drawing area map
- 硬刚甲方后:中国移动 4908 万大单被废
- You haven't connected to the proxy server. There may be a problem or the address is incorrect (how to check the proxy server IP)
- 20210419 combined sum
- In the first half of the year, the number of fires decreased by 27.7%. Guangdong will improve the fire safety quality of the whole people in this way
- 广东财政多举措助力稳住粮食安全“压舱石”
- Shake quickly to rescue the "frustrated person"
- Lonely young people can't quit jellycat
- 评价自动化测试优劣的隐性指标
猜你喜欢

Chapter 7 exception handling

Wechat applet session holding

2021-3-22-directed graph sorting

Watermelon book chapter 3 (first & second)

Interviewer: how can you close an order without using a scheduled task?

I do live e-commerce in tiktok, UK

Go Beginner (4)

Chapter 10 enumeration classes and annotations

J9 number theory: how long is the mainstreaming of decentralized identity?

Use redis' sorted set to make weekly hot reviews
随机推荐
Image segmentation vs Adobe Photoshop (PS)
Openpyxl drawing area map
【产品】关于微信产品分析
In the first half of the year, the number of fires decreased by 27.7%. Guangdong will improve the fire safety quality of the whole people in this way
The strongest distributed locking tool: redisson
Redis data type
POJ1611_The Suspects
After Party A's hard work, 49.08 million orders of China Mobile were scrapped
浪潮之巅——读书笔记+摘录+感悟
Kazoo tutorial
deeplab系列详解(简单实用年度总结)
Newticker uses
20210408 longest public prefix
Unity 2D game tutorial
系统临时文件的写和读:createTempFile和tempFileContent[通俗易懂]
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
Example of MATLAB dichotomy (example of finding zero point by dichotomy)
Do you really understand the underlying data structure skip list of Zset in redis?
(07) flask is OK if you have a hand -- flask Sqlalchemy