Company: InMobi
Difficulty: medium
Employee Reportees Problem Description A company has N employees numbered 1 through N. Employee 1 is the CEO and reports to nobody; every other employee reports, directly, to exactly one other employee. For every employee from ID 1 through ID N, determine and print the total headcount that ultimately reports up to them, counting both direct reports and reports of reports. Input: The first line is an integer N, the total number of employees. The next N-1 lines each contain two space-separated integers, n1 and n2, indicating that n2 is the manager of n1. Output: Print N space-separated integers. The first integer should be the total number of reportees for employee ID 1, the second for employee ID 2, and so on, up to employee ID N. Examples Example 1: Input: 5 2 1 3 2 4 1 5 3 Output: 4 2 1 0 0 Explanation: Employee 2's manager is 1. Employee 3's manager is 2. Employee 4's manager is 1. Employee 5's manager is 3. Drawing this out as a reporting tree rooted at the CEO (ID 1) gives: Employe