Time limit
2s
Memory limit
128 MB
A company's work is processed from the bottom of its organization chart upward. Terminal employees perform their tasks first, and an employee may start only after every employee below them has finished. The whole process ends when the president finishes their task. Every employee's task takes exactly 1 unit of time from start to finish.
Every employee except the president has exactly one direct supervisor. The company wants to reduce its staff. A task belonging to a removed employee may be performed by any remaining employee, and one employee can perform only one task at a time. Remaining employees may perform tasks for other positions freely, but the total completion time must not become longer than before any employees were removed.
Given the direct-supervisor relationship, find the original minimum completion time and the maximum number of employees that can be removed while preserving that time.
The first line contains an integer N(1 <= N <= 100,000), the number of employees. The next N lines give, in order, the direct supervisor number of employees 1, 2, ..., N. For the president, -1 is given.
Print the minimum completion time needed when all employees are present on the first line. On the second line, print the maximum number of employees that can be removed while preserving that time.
One optimal schedule can be viewed as follows.