#P5886. Hello, 2020!

Hello, 2020!

Description

In this contest, there are nn problem setters and mm contestants.

The problem setters are numbered from 11 to nn, and the contestants are numbered from 11 to mm.

After the contest ends, the final ranking of contestants is a permutation of 11 to mm, and all ranks are distinct.

After registration ends, the ii-th problem setter looked at the registration list and said to the other problem setters: “I think only these kik_i contestants might finally rank first. They are ai,1,ai,2,,ai,kia_{i,1},a_{i,2},\dots,a_{i,k_i}. 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 nn predictions made by these problem setters, and also told you that exactly pp 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 n,m,pn,m,p, representing the number of problem setters, the number of contestants, and the number of correct predictions.

The next nn lines each start with a non-negative integer kik_i, indicating how many contestants the ii-th problem setter predicts could finally rank first; then follow kik_i positive integers ai,1,ai,2,,ai,kia_{i,1},a_{i,2},\dots,a_{i,k_i}, 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 (6%6\%): n20n\leq 20, m20m\leq 20.

Subtask 2 (30%30\%): n100n\leq 100, m100m\leq 100, ki104\sum k_i \leq 10^4.

Subtask 3 (24%24\%): n1000n\leq 1000, m1000m\leq 1000.

Subtask 4 (40%40\%): no special constraints.

Constraints for all data: 1n1051\leq n\leq 10^5, 1m1061\leq m\leq 10^6, 0ki1060\leq \sum k_i \leq 10^6, 0pn0\leq p\leq n.

Translated by ChatGPT 5