It is recently discovered that someone in'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 to help them resolve their dilemma.
There are a total of people in '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:
- The person is already infected
- The person has class with the infected person
- The person has class with someone that is potentially infected
Please write a program to helpdetermine who is potentially infected.
For all subtasks:
Subtask 1 [80%]
Subtask 2 [20%]
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 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.
9 4 3 1 2 3 4 2 3 4 5 3 6 7 8 2 3 9
6 1 2 3 4 5 9