LogiQuest

288. Tree Height from Parent Array

EasyTrees

Node i (0-based) has parent p[i]; the root has parent -1. Print the height of the tree (number of edges on the longest root-to-leaf path).

Input format

Line 1: n Line 2: n parents

Output format

The height.

Example 1

Input

5
-1 0 0 1 3

Output

3

Example 2

Input

1
-1

Output

0

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…