#P5886. Hello, 2020!
Hello, 2020!
Description
In this contest, there are problem setters and contestants.
The problem setters are numbered from to , and the contestants are numbered from to .
After the contest ends, the final ranking of contestants is a permutation of to , and all ranks are distinct.
After registration ends, the -th problem setter looked at the registration list and said to the other problem setters: “I think only these contestants might finally rank first. They are . No one else can possibly end up in first place.”
The problem setter of the problem on your screen learned in advance, through a time tunnel, who the contestant that finally ranks first is.
The problem setter told you all predictions made by these problem setters, and also told you that exactly problem setters’ predictions are correct.
Please determine which contestants could possibly end up in first place, and output their IDs in increasing order.
Input Format
Read the input from standard input.
The first line contains three positive integers , representing the number of problem setters, the number of contestants, and the number of correct predictions.
The next lines each start with a non-negative integer , indicating how many contestants the -th problem setter predicts could finally rank first; then follow positive integers , indicating the contestant IDs that this problem setter predicts could finally rank first.
Output Format
Write the output to standard output.
The first line outputs a non-negative integer, indicating the number of contestants who could possibly end up in first place.
The second line outputs these contestants’ IDs in increasing order.
4 3 2
2 2 3
1 1
3 1 2 3
2 1 3
1
2
Hint
Subtask 1 (): , .
Subtask 2 (): , , .
Subtask 3 (): , .
Subtask 4 (): no special constraints.
Constraints for all data: , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号