#K75397. Calculate Employee Hierarchy Depth

    ID: 34410 Type: Default 1000ms 256MiB

Calculate Employee Hierarchy Depth

Calculate Employee Hierarchy Depth

In a hierarchical organization, every employee (except the CEO) has exactly one immediate supervisor. Given the number of employees and a list where each element represents the immediate supervisor of the corresponding employee (with -1 indicating no supervisor), your task is to calculate the depth of each employee in the organizational hierarchy. The depth of an employee is defined as follows: if an employee has no supervisor (i.e. the value is -1), then their depth is 1; otherwise, the employee's depth is one more than the depth of their supervisor. Note that some organizations might have more than one independent hierarchy (i.e. multiple roots).

Input sample:
6
-1 1 1 3 3 4

The output for this sample should be:
1 2 2 3 3 4

inputFormat

The input is read from standard input (stdin). The first line contains an integer ( n ) representing the number of employees. The second line contains ( n ) space-separated integers, where the ( i )-th integer represents the immediate supervisor of employee ( i ) (using 1-indexing for supervisors). A value of -1 indicates that the employee has no supervisor (i.e., is a root in the hierarchy).

outputFormat

Output a single line with ( n ) space-separated integers. The ( i )-th integer is the depth of employee ( i ) in the hierarchy, where the depth of an employee with no supervisor is 1, and for any other employee, it is one more than the depth of their supervisor.## sample

6
-1 1 1 3 3 4
1 2 2 3 3 4

</p>