#K11941. Calculate Social Influence in a Directed Network

    ID: 23580 Type: Default 1000ms 256MiB

Calculate Social Influence in a Directed Network

Calculate Social Influence in a Directed Network

In a social network, influence flows from one user to another through direct or indirect connections. You are given a directed graph with n users (nodes) and m directed edges. Each directed edge (u, v) represents that user u can directly influence user v.

Your task is to compute for every user u the total number of distinct users v (with v ≠ u) such that there exists a directed path from u to v. In mathematical terms, for each user u, you must calculate:

\(I(u)=\left|\{ v\neq u : \exists \; \text{a path from } u \text{ to } v \}\right|\)

The network may contain cycles. Make sure to exclude the starting node itself when counting its influence.

inputFormat

The first line contains two integers n and m, representing the number of users and the number of directed edges respectively.

The following m lines each contain two integers u and v, indicating that there is a directed edge from user u to user v.

outputFormat

Output a single line with n space-separated integers. The i-th integer should denote the number of users influenced by user i (1-indexed), which is the number of nodes reachable from user i (excluding i itself).

## sample
4 3
1 2
2 3
3 4
3 2 1 0

</p>