QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#11882. The Tournament

Statistics

The International X-Game Federation organises a tournament in which programmes that play this game participate. programmes numbered from to take part in the competition. The rules of the tournament are as follows: while there remains more than one programme in the tournament, two of them (distinct) are randomly chosen to play a game. The defeated one (there are no draws in the X-Game) drops out of the tournament and the whole procedure is repeated. The sole programme which stays in the tournament after all games have been played is the winner.

The federation has a table of results of previous tournaments. It is known, that the programmes play deterministically (i.e. in repeatable fashion) and in exactly the same way as in previous tournaments. So, if two programmes have already played one against another then their next game will end with the same result. If, however, they have never played against each other, the outcome of the game cannot be predicted - both have a chance of winning. The federation would like to know a list of all programmes which have a chance of winning the tournament.

Write a programme which:

  • reads from the standard input the number of participating programmes and the table of results of their previous games,
  • determines all programmes which have a chance of winning the tournament,
  • writes the outcome to the standard output.

Input

The first line of the input contains an integer $n$, $1 ≤ n ≤ 100\,000$. The next $n$ lines contain the table of results of previous games: $(i+1)$st line contains an integer $k_i$, $0 ≤ k_i ≤ n$, followed by $k_i$ numbers of programmes, not equal to $i$, in increasing order - those are the numbers of programmes, with which the programme $i$ has previously won. The numbers in lines are separated by single spaces. The number of all known results of previous games does not exceed $1\,000\,000$.

Output

The first and only line of the standard output should contain the number $w$ of programmes which have a chance of winning the tournament, followed by $w$ numbers identifying those programmes, in increasing order. The numbers should be separated by single spaces.

Example

Input

4
2 2 3
0
1 2
1 2
problem_11882_1.gif

Output

3 1 3 4
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.