AtCoder Grand Contest 009
B
Tournament
AtCoder
⌀ 1685
原题
← AC →
翻译中…

Problem Statement

翻译中…

$N$ contestants participated in a competition. The total of $N-1$ matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.

翻译中…

After each match, there were always one winner and one loser. The last contestant standing was declared the champion.

翻译中…

image Figure: an example of a tournament

翻译中…

For convenience, the contestants were numbered $1$ through $N$. The contestant numbered $1$ was the champion, and the contestant numbered $i(2 ≦ i ≦ N)$ was defeated in a match against the contestant numbered $a_i$.

翻译中…

We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.

翻译中…

Find the minimum possible depth of the tournament.

翻译中…

The formal description of the structure of the tournament is as follows. In the $i$-th match, one of the following played against each other:

翻译中…
  • Two predetermined contestants
  • One predetermined contestant and the winner of the $j$-th match, where $j(j<i)$ was predetermined
  • The winner of the $j$-th match and the winner of the $k$-th match, where $j$ and $k$ $(j,k<i, j ≠ k)$ were predetermined
翻译中…

Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.

翻译中…

Constraints

翻译中…
  • $2 ≦ N ≦ 10^5$
  • $1 ≦ a_i ≦ N(2 ≦ i ≦ N)$
  • It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
a_2
:
a_N

翻译中…

Output

翻译中…

Print the minimum possible depth of the tournament.

翻译中…

样例

Input #1
5
1
1
2
4
Output #1
3
The following tournament and the result of the matches are consistent with the given information: - In the first match, contestants $4$ and $5$ played against each other, and contestant $4$ won. - In the second match, contestants $2$ and $4$ played against each other, and contestant $2$ won. - In the third match, contestants $1$ and $3$ played against each other, and contestant $1$ won. - In the fourth match, contestants $1$ and $2$ played against each other, and contestant $1$ won. ![783f7be9c88350e31963edba8a958879.png](https://atcoder.jp/img/agc009/783f7be9c88350e31963edba8a958879.png) The depth of this tournament is $3$, since contestant $5$ must play three matches in order to win the championship. There is no tournament with depth $2$ or less that is consistent with the given information, thus the output should be $3$.
Input #2
7
1
2
1
3
1
4
Output #2
3
Input #3
4
4
4
1
Output #3
3
题目信息
题号
agc009_b
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。