QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Hackable ✓

#61. Cut Cut Cut!

統計

You are given a directed acyclic graph $G=(V,E)$ with $n$ vertices and $m$ edges. The $i$-th edge is connected from vertex $u_i$ to vertex $v_i$. After a long observation, you find that the outdegree $1$ does not exceed $20$.

For each $2 \leq i \leq n$, you want to know the minimum number of edges you need to delete, so that there is no path between the vertex $1$ and the vertex $i$ that does not pass through the edge you deleted.

Input

The first line contains two integers $n$ and $m$ $(1 \leq n \leq 10^5, 1 \leq m \leq 3 \times 10^5)$ - the number of the vertices and the number of the edges.

The next $m$ lines describes the graph $G$:

  • The $i$-th line of these lines contains two integers $u_i, v_i$ ($1 \leq u_i \mathbf{<} v_i \leq n$) - an edge between the vertex $u_i$ and $v_i$.

It is guaranteed that there are no multiple edges in the graph, and there are no more than $20$ edges satisfy that their starting vertex is vertex $1$.

Output

Output a single line contains $n - 1$ integers - the $i$-th of them describes the minimum number of edges you have to delete.

Examples

Input 1

3 3
1 2
1 3
2 3

Output 1

1 2

Explanation 1

For $i = 2$, the optimal solution is to delete edge $(1, 2)$.

For $i = 3$, the optimal solution is to delete edge $(1, 2)$ and $(1, 3)$.

Input 2

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

Output 2

1 1 1 2 1 0 0

Input 3 / Output 3

You can find them in the additional files.

Input 4 / Output 4

You can find them in the additional files.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.