#P2244. 选举预测

选举预测

Description

The first stage of the election is a debate tournament. Its rules are as follows: if the number of remaining candidates is greater than 22, then any 22 of them are chosen to debate. The loser exits the tournament, and the winner stays. This continues until only one candidate remains, who is then the winner of the debate tournament.

The winner of the debate tournament will have an advantage in the subsequent election, so people are very concerned about the result of this tournament, including the historian Geheimnis.

He gathered information on all nn candidates and found that if two candidates have competed before, then the result is very unlikely to change when they meet again (you may assume it will not change). Based on the intelligence Geheimnis has, you need to determine which candidates could possibly become the winner.

Input Format

The first line contains a positive integer nn, the number of candidates.

Then follow nn lines. Candidates are indexed from 11. The (i+1)(i+1)-th line describes candidate ii. The first number is kk, followed by kk indices, indicating the candidates that candidate ii has previously defeated.

Output Format

Output one line. The first number is cc, the number of candidates who can possibly win; then output cc numbers denoting their indices.

4
2 2 3
0
1 2
1 2

3 1 3 4

Hint

Constraints
For 50%50\% of the testdata, n200n \le 200.
For 100%100\% of the testdata, n106n \le 10^6, and the number of win–loss pairs does not exceed 10610^6.

Translated by ChatGPT 5