cho.sh
Notes
Loading...

News Broadcast

Time limit

2s

Memory limit

128 MB

Problem

A company has employees numbered from 0 to N-1, and employee 0 knows an important piece of news that must reach the entire company. The direct-manager relationship forms a tree. Every employee except employee 0 has exactly one direct manager, and every employee is a direct or indirect subordinate of employee 0.

An employee who has heard the news may call only their direct subordinates. One employee can call only one person at a time, and each call takes exactly 1 minute. After a subordinate receives the call, that subordinate may start calling their own direct subordinates in the same way.

Choose the calling order for every employee so that all employees hear the news as early as possible, and output that minimum time.

Input

The first line contains the number of employees N.

The second line contains the direct manager number for each employee from 0 through N-1. Employee 0 has no manager, so its value is -1. Every other manager number is a nonnegative integer. The input always describes a valid tree.

N is a positive integer not greater than 50.

Output

Print the minimum number of minutes needed for every employee to hear the news.