6819.Subordinates

Time Limit: 1s Memory Limit: 512MB

Given the structure of a company, your task is to calculate for each employee the number of their subordinates.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the number of employees. The employees are numbered $1,2,\dots,n$ , and employee $1$ is the general director of the company.

After this, there are $n-1$ integers: for each employee $2,3,\dots,n$ their direct boss in the company.

  • $1 \le n \le 2 \cdot 10^5$

Output Format(To the terminal/stdout)

Print $n$ integers: for each employee $1,2,\dots,n$ the number of their subordinates.

Sample Input

Copy
5
1 1 2 3
 \n
 · · · \n

Sample Output

Copy
4 1 1 0 0
 · · · · \n
Source: CSES, Tree Algorithms, 1674

Submit

请先 登录

© 2025 FAQs