QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#788. Dominator Tree

Statistics

Given a directed graph $G=(V,E)$ with $n$ vertices, it is guaranteed that vertex $1$ can reach all other vertices.

We say that vertex $u$ dominates vertex $v$ if, after removing vertex $u$, there is no path from $1$ to $v$. Specifically, every vertex dominates itself.

You need to calculate, for each vertex, how many vertices it dominates.

Input

The first line contains two integers $n$ and $m$.

The next $m$ lines each contain two integers $u$ and $v$, describing a directed edge from $u$ to $v$.

Output

Output a single line containing $n$ integers, where the $i$-th integer describes the number of vertices dominated by vertex $i$.

Constraints

For all test cases, $1 \leq n \leq 5 \times 10^5, 1 \leq m \leq 10^6$.

Examples

Input 1

3 3
1 2
1 3
2 3

Output 1

3 1 1

Input 2

5 7
1 2
1 3
1 5
2 4
2 6
5 6
6 7

Output 2

5 2 1 1 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.