#K91202. Employee Headcount in Corporate Hierarchy

    ID: 37923 Type: Default 1000ms 256MiB

Employee Headcount in Corporate Hierarchy

Employee Headcount in Corporate Hierarchy

You are given a company hierarchy with N employees labeled from 1 to N. Some employees directly report to others forming one or more tree structures (forests). For each employee i, define its headcount as:

$$headcount(i) = 1 + \sum_{j \in children(i)} headcount(j) $$

The task is to compute the headcount for every employee. An employee with no subordinate has a headcount of 1. The input provides the number of employees, followed by the number of direct report relationships, and then the list of pairs A B meaning employee A directly reports to employee B.

Note: There can be multiple top-level managers (employees who do not report to anyone). Ensure your program works for all such cases.

inputFormat

The first line contains an integer N (1 ≤ N ≤ 105), the number of employees.

The second line contains an integer M (0 ≤ M ≤ N-1), the number of direct reporting relationships.

The following M lines each contain two space-separated integers A and B indicating that employee A directly reports to employee B.

outputFormat

Output a single line with N integers where the i-th integer is the headcount of employee i. The numbers should be separated by a space.

## sample
1
0
1

</p>