#P15505. [CEOI 2012] Sailing Race

    ID: 15387 远端评测题 3000ms 32MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2012Special JudgeCEOI(中欧)

[CEOI 2012] Sailing Race

Description

The annual sailing race is organized on a round shape lake. There are NN harbors, numbered from 11 to NN around the lake counterclockwise. The race consists of several stages, where each stage runs on a straight line from one harbor to another, and the race track can only meet a harbor at most once. The organizers want to create a race track that contains the highest possible number of stages. They must keep in mind that a sailboat at a given harbor may only go to some specific harbors on a direct route. Fortunately, for each harbor AA they have the list of direct destinations from AA, i.e. a list of other harbors to which a sailboat can go on a straight line from AA. Generally, the race track consists of non-intersecting stages, to avoid the collision of sailboats. This year, however, a new technology is available, with which one crossing may be allowed if it lies on the first stage. So if the race track starts at harbor S and the next harbor in the track is TT then at most one stage can cross the first stage STS-T. The organizers may decide to allow a crossing like this, or rather choose the classical design with non-intersecting stages.

You are to write a program that computes a race track of the given type containing the highest possible number of stages.

Input Format

The first line of the input contains two integers, the first number N(1N500)N (1 \le N \le 500) is the number of harbors and the second number kk is the type of the required race track. If kk is 00 then a classical track (without crossings) is required, while if kk is 11 then the track may contain at most one crossing, as specified above. The next NN lines contain the list of direct destinations from the harbors. The (i+1)(i+1)-th line contains the list for harbor ii, a space-separated list of integers, terminated by 00.

Output Format

The first line of the output contains one integer MM, the maximal number of stages that a race track of the given type can contain. The second line contains the identifier number of the starting harbor of one such race track. If there are multiple solutions, your program should output only one; it does not matter which one.

7 1
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0

5
2

Hint

Limitations

In 40%40\% of the test cases k=0k=0.
In 50%50\% of the test cases NN is at most 100100.

No partial score is awarded for a correct first line.