Polish version    English version  
  History of OI -> VI OI 1998/1999 -> 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
VI OI 1998/1999
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
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
VI Olimpiada Informatyczna 1998/1999

Task: GRO
Author:
Speleology

I stage contest  

A team of speleologists organizes a training in the Grate Cave of Byte Mountains. During the training each speleologist explores a route from Top Chamber to Bottom Chamber. The speleologists may move down only, i.e. the level of every consecutive chamber on a route should be lower then the previous one. Moreover, each speleologist has to start from Top Chamber through a different corridor and each of them must enter Bottom Chamber using different corridor. The remaining corridors may be traversed by more then one speleologist. How many speleologists can train simultaneously? 

Task

Write a program which:

  • reads the cave description from the text file GRO.IN,
  • computes the maximal number of speleologists that may train simultaneously,
  • writes the result to the text file GRO.OUT.

Input

In the first line of the text file GRO.IN there is one integer n (2<=n<=200), equal to the number of chambers in the cave. The chambers are numbered with integers from 1 to n in descending level order - the chamber of grater number is at the higher level than the chamber of the lower one. (Top Chamber has number 1, and Bottom Chamber has number n). In the following n-1lines (i.e. lines 2,3,...,n) the descriptions of corridors are given. The (i+1)-th line contains numbers of chambers connected by corridors with the i-th chamber. (only chambers with numbers grater then i are mentioned). The first number in a line, m, 0<=m<=(n-i+1), is a number of corridors exiting the chamber being described. Then the following m integers are the numbers of the chambers the corridors are leading to. 

Output

Your program should write one integer in the only line of the text file GRO.OUT. This number should be equal to the maximal number of speleologists able to train simultaneously, 

Example

For the input file GRO.IN:

12
4 3 4 2 5
1 8
2 9 7
2 6 11
1 8
2 9 10
2 10 11
1 12
2 10 12
1 12
1 12

describing the following cave:

the correct answer is a text file GRO.OUT:

3



Print friendly version