Polish version    English version  
  History of OI -> VII OI 1999/2000 -> 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
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
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
Niebieskie ksi.eczki
VII Olimpiada Informatyczna 1999/2000

Task: POD
Author: Marcin Kubica
Signatures

II stage contest  

There are clerks and commanders employed in Byteland Security Agency (BSA). The records of all the clerks can be found in the BSA archives. In each folder there is a signature of the clerk and signatures of workers (clerks or commanders), who vouche for his/her loyalty. Every newly engaged clerk has to obtain at least one guarantee. In the course of time, list of guarantors can increase. BSA has found out lately, that the circle of commanders has been infiltrated by a spy from hostile Microsoftland. Next spies were employed in BSA on clerks positions thanks to the guarantee of a spy-commander and/or other employed spies. Such spies have guarantees exclusively from workers being spies.

Reliability of a clerk can be questioned, if he has not indirectly got guarantees from any commander, who is not a spy, i.e. there is no such sequence of BSA workers p1, p2,..., pk, that p1 is commander not being a spy, pk is given clerk and (for i=1,..., k-1) pi vouches for pi+1.

If an assumption that a commander is a spy, caused that reliability of a clerk became questioned, this clerk would be suspected of spying. The command of BSA would want to see the list of these clerks, as soon as possible!

Example

Commanders: Alice, Gregor
Clerks: Bob (vouched for by Alice), Charlie (vouched for by Bob), David (vouched for by Bob and by Charlie), Eve (vouched for by Alice and Gregor), Frank (vouched for by Eve), Henry (vouched for by Gregor and Isabelle), Isabelle (vouched for by Gregor and Henry).
Suspected: Bob, Charlie, David, Henry, Isabelle.

Task

Write a program, which:

  • reads number of commanders and clerks in BSA and informations about guarantees, from the text file POD.IN
  • determines a list of clerks suspected of spying,
  • writes the result to the text file POD.OUT.

Input

The first line of the text file POD.IN consists of exactly one positive integer n, 1 <= n <= 500, standing for the number of workers of BSA. The employees are numbered from 1 to n. The next n lines contain descriptions of guarantees. In the (i+1)-th line of the file there is the description of guarantees given to the i-th worker. It is a sequence of integers separated by single spaces. The first number in this sequence 0 < mi, equals to the number of guarantees given to the i-th worker. The next mi integers are the numbers of workers, who have guaranteed the truthfullness of the i-th worker. (Thus the number of elements in the sequence in the (i+1)-th line equals mi + 1). Commanders are those workers, who have not been vouched for by anybody.

Output

Your program should:

  • write in the consecutive lines of the text file POD.OUT sequence of positive integers being numbers of clerks suspected of spying - if such clerks exist. These numbers should be written in increasing order, exactly one in each line,
  • write in the first and the only line of the output file POD.OUT exactly one word BRAK - if such clerks do not exist.

Example

For the input file POD.IN

9
0
1 1 
1 2
2 2 3
2 1 7
1 5
0
2 7 9
2 7 8

the correct result is the output file POD.OUT

2
3
4
8
9



Print friendly version