z-daniels
The map of the roads in the Z land is in the form of a tree (each road with length 1). Little Z wants to find the length of the longest possible route. Then he will take his Jack Daniels, and he can drink, but let his friends drive!
InputFrom the first line of the standard input read an integer n (1 <= n <= 500000) representing the number of cities in Z-land. Let the cities be numbered from 0 to n-1. From each of the next n-1 lines read an integer bi, that integer represents that there is a path between i and bi, where i = 1 for the first line you read, and i=n-1 for the last line you read.
OutputTo the standard output write one integer, the length of the longest route in z-land
Input:
Output:
5
0
0
0
0Output:
2Input:
Output:
5
0
1
2
3Output:
4Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.