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: NAR
Author: Marcin Kubica
Skiers

I stage contest  

A ski team organizes a training on the Bytemountain. There is one ski lift on the northern slope of the mountain. All the ski runs lead from the upper ski lift station to the bottom one. During the training the team members will start together from the upper station and meet at the bottom one. Apart from these two points, the ski runs of the competitors cannot intersect, nor adhere to each other. All ski runs always have to lead downwards.

A map of ski runs consists of net of clearings connected by glades. Every clearing lies on a different height. Two clearings can be joint directly with at most one glade. While skiing downhill from the upper to the bottom station of ski lift, one can choose way to visit any clearing (but maybe not all in one downhill run). Ski runs can intersect only on the clearings and do not lead through tunnels, or flyovers.

Task

Write a program, which:

  • reads the map of ski runs from the text file NAR.IN,
  • determines maximum number of competitors who can participate in training,
  • write the result to the text file NAR.OUT.

Input

In the first line of the input file NAR.IN, there is an integer n, that equals to the number of the clearings, 2 <= n <= 5 000.

In each of the next n-1 lines there is a sequence of integers separated by single spaces. Numbers in the (i+1)-th line describe, to which clearings the downhill glades from the i-th clearing lead. First integer in the line - k is the number of these clearings, and the following k integers are their numbers, which are ordered according to the arrangement of glades leading to them, in east to west direction. The clearings are numbered from 1 to n. The upper station of the ski lift can be found on the clearing number 1 and the bottom one on the clearing number n.

Output

The first and the only one line of the output file NAR.OUT should consist of exactly one integer - the maximum number of skiers able to take part in the training.

Example

For the input file NAR.IN

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

the correct result is the output file NAR.OUT:

3



Print friendly version