Polish version    English version  
  History of OI -> XI OI 2003/2004 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Stage III
Rules
For contestants
Helpful resources
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
XI Olimpiad in Informatics 2003/2004

Task: tur

The Tournament

II stage competition  
Source file: tur.xxx (xxx=pas,c,cpp)
Memory limit: 32 MB

Alternative formats: PostScript

The International X-Game Federation organises a tournament in which programmes that play this game participate. n programmes numbered from 1 to n 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 n-1 games have been played is the winner.

The fedaration has a table of results of previous tournaments. It is known, that the programmes play deterministicly (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.

Task

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+1st 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

For the input data:


4
2 2 3
0
1 2
1 2

the correct outcome is:

3 1 3 4



Print friendly version