P2244 Election Prediction
Background
As the situation stabilizes, the term of the Academy of Sciences' leader, Dunkelheit, is about to end soon. Therefore, the election for the new leader of the Academy of Sciences, which carries extraordinary significance, is about to begin.
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 $2$, then any $2$ 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 $n$ 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 $n$, the number of candidates.
Then follow $n$ lines. Candidates are indexed from $1$. The $(i+1)$-th line describes candidate $i$. The first number is $k$, followed by $k$ indices, indicating the candidates that candidate $i$ has previously defeated.
Output Format
Output one line. The first number is $c$, the number of candidates who can possibly win; then output $c$ numbers denoting their indices.
Explanation/Hint
Constraints
For $50\%$ of the testdata, $n \le 200$.
For $100\%$ of the testdata, $n \le 10^6$, and the number of win–loss pairs does not exceed $10^6$.
Translated by ChatGPT 5