#K90832. Employee Influence in Email Communication Networks

    ID: 37840 Type: Default 1000ms 256MiB

Employee Influence in Email Communication Networks

Employee Influence in Email Communication Networks

In many organizations, email communications form a complex network of influence among employees. Each directed email from one employee to another may allow the sender's influence to propagate indirectly through a chain of emails. In this problem, you are given a directed graph representing email communications. The graph has (n) nodes representing employees and (m) directed edges where an edge from node (u) to node (v) indicates that employee (u) sends an email to employee (v).

For each employee (i), you are required to compute its influence, which is defined as the number of distinct employees (other than (i) itself) that can reach employee (i) through a sequence of emails. Formally, for each employee (i), find the number of nodes (j \ (j \neq i)) such that there exists a path from (j) to (i) in the graph.

Input Format: The input will be given via standard input.
Output Format: Output the influence values for all employees in order from 1 to (n), separated by spaces.

For example, if (n = 5) and the emails are given by the edges: [ (1,2),\ (2,3),\ (3,4),\ (4,5) ] The influences for employees 1 through 5 are: [ 0,\ 1,\ 2,\ 3,\ 4 ] since: (1) cannot be reached by any other employee, (2) can be reached by employee (1), (3) by employees (1, 2), and so on.

inputFormat

The first line contains two integers (n) and (m), where (n) is the number of employees and (m) is the number of emails. This is followed by (m) lines, each containing two integers (u) and (v) representing a directed edge from employee (u) to employee (v).

outputFormat

Output a single line with (n) integers separated by spaces. The (i^{th}) integer represents the number of different employees that can send an email (directly or indirectly) to employee (i).## sample

5 4
1 2
2 3
3 4
4 5
0 1 2 3 4