CSES - Subordinates

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 512M
Input: stdin
Output: stdout

Nguồn bài:
https://cses.fi/problemset/task/1674
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

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

Input

  • 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.

Output

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

Constraints

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

Example Input

5
1 1 2 3

Example Output

4 1 1 0 0

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.