Problem statement
We have a company with $ N $ employees, each of whom is assigned a $ 1, ..., N $ employee number. All employees, except those with employee number 1, have just $ 1 $ in direct reports with a lower employee number than you. When $ X $ is a direct boss of $ Y $, $ Y $ is said to be a direct report of $ X $. Employee number $ i $ is given the employee number of the employee's direct supervisor is $ A_i $. Find out how many direct reports each employee has.
Constraints
Find out how many elements of A are input, and output those values in order.
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
for i in range(1, N + 1):
print(c[i])
collections.Counter You can find the number of each element in the array by using the Counter class of the collections library.
l = [1,1,2,2,2,3,4,4]
c = collections.Counter(l)
print(c)
# Counter({1: 2, 2: 3, 3: 1, 4: 2})
Recommended Posts