## DMOPC '16 Contest 2 P2 - Ebola Outbreak

View as PDF

Points: 7 (partial)
Time limit: 0.3s
Java 8 1.0s
Python 3.0s
Memory limit: 64M
Python 1G

Authors:
Problem type

It is recently discovered that someone in lolzballs's school has contracted Ebola (an extremely dangerous viral disease). The school administrators were frightened that more people would become infected and decided to isolate those who are potentially infected. They reached out to lolzballs to help them resolve their dilemma.

There are a total of people in lolzballs's school, numbered to . There are a total of classes, and the class has a size of . Each person can be part of or more classes. Initially, the person numbered is infected with Ebola.

A person is deemed potentially infected if:

1. The person is already infected
2. The person has class with the infected person
3. The person has class with someone that is potentially infected

Please write a program to help lolzballs determine who is potentially infected.

#### Input Specification

On the first line of the input are 2 integers and .

This line is followed by lines which describe each class.

Every line begins with an integer (), which represents the number of students in that class. integers follow, indicating the people in the class.

#### Output Specification

Output the number of potentially infected people on the first line of the output.

On the second line, please output the sorted list of potentially infected people, separated by a space.

#### Sample Input

9 4
3 1 2 3
4 2 3 4 5
3 6 7 8
2 3 9

#### Sample Output

6
1 2 3 4 5 9

• commented on Nov. 23, 2020, 11:33 p.m.

2020: hold my corona

• commented on Nov. 9, 2016, 1:45 a.m.

is 1 always going to be the second number on line 2?

• commented on Nov. 9, 2016, 2:21 a.m.

No, it is not. The person numbered can be part of any group, or no group at all.

• commented on Nov. 8, 2016, 9:46 p.m.

Ebola isn't spread by being near someone who has it. Ebola is spread through direct contact with blood or bodily fluids from someone who has or died with Ebola.