#K59797. Company Hierarchy Depth
Company Hierarchy Depth
Company Hierarchy Depth
You are given information about a company's hierarchy. The company consists of N employees. Each employee is assigned an ID, and for every employee (except the CEO), the ID of their manager is provided. The CEO is identified by a manager value of -1. Your task is to determine the maximum depth of the hierarchy tree which represents the longest chain of command in the company.
The depth is defined as the number of employees in the longest chain from the CEO (root) down to the most subordinate employee.
Note: The input format guarantees that there is exactly one CEO. Every other employee has exactly one manager, and the relationships form a valid tree.
inputFormat
The first line of input contains a single integer N (1 ≤ N ≤ 105) representing the number of employees.
The next N lines each contain two space-separated integers. The first integer is the employee ID and the second is the manager ID. The manager ID is -1 for the CEO.
It is guaranteed that the employees are numbered uniquely and the hierarchy forms a valid tree.
outputFormat
Output a single integer which is the maximum depth of the company's hierarchy.
## sample4
1 -1
2 1
3 1
4 3
3
</p>