Graph Theory37 sections · 1633 units
Open in Course

Problem - Subordinates

(CSES - Subtree size)

You have a tree with n employees. Employee 11 is the boss (root). For each employee, count how many subordinates they have. Subordinates are all employees in their subtree, excluding the employee themselves. Input: First line is n (number of employees). Second line has n1n-1 numbers: the boss of employees 22, 33,., n.

Output: n numbers, the subordinate count for each employee. Example: If employee 22 has employees 33 and 44 below them, and employee 33 has employee 55, then employee 22 has 33 subordinates (employees 33, 44, 55).