Subordinates
Subordinates
A company has n employees numbered 1..n. Employee 1 is the general director.
For every employee 2..n, you are given the number of their direct boss. This defines the company hierarchy (a boss can have many direct employees).
Your task is to compute, for each employee 1..n, how many subordinates they have in total (both direct and indirect).
Input:
- First line: integer
n— number of employees. - Second line:
n-1integersp2 p3 ... pnwherepiis the direct boss of employeei.
Output:
- Print
nintegers: for each employee1..n, the number of their subordinates.
Constraints:
1 ≤ n ≤ 2 · 10^5
Example:
Input:
5
1 1 2 3
Output:
4 1 1 0 0