Critical Road

시간 제한1초메모리 제한2048 MB

요약
노드 1에서 모든 노드에 도달할 수 있는 DAG가 주어질 때, 각 노드 i로 가는 모든 경로에 포함되는 간선의 개수를 구한다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

The City of ICPC is preparing for a party for its anniversary. As the mayor of the city, you would like to hold a parade in each of the districts in the city.

The parade route can be represented as a Directed Acyclic Graph. There are NN nodes (numbered from 11 to NN) that represent the districts in the city. There are MM directed edges (numbered from 11 to MM) that represent the one directional roads. By using road jj, the parade can move from district U_jU\_j to V_jV\_j, but not the other way around. It is known that all districts can be visited by the parade from the City Center, which resides in district 11.

A road is ii-critical if the road is used in all paths from district 11 to district ii. It is possible for a road to be ii-critical for several values of ii. You want to assess the number of ii-critical roads for each ii, as they are pivotal for the parade.

For each ii that satisfies 1≤i≤N1 ≤ i ≤ N, determine the number of ii-critical roads.

입력

The first line consists of two integers NN MM (2≤N≤100,0002 ≤ N ≤ 100\\, 000; N−1≤M≤200,000N - 1 ≤ M ≤ 200\\, 000).

Each of the next MM lines consists of two integers U_jU\_j V_jV\_j (1≤U_j,V_j≤N1 ≤ U\_j , V\_j ≤ N). The edges form a directed acyclic graph, and every node can be visited from node 11. Furthermore, there will be no multi-edges, i.e., there will be at most one edge that directs two nodes.

출력

Output NN integers in a single line. Each of the integers represents the number of ii-critical roads.

예제2

  1. 예제 1

    입력
    6 7
    1 2
    2 3
    2 4
    1 3
    3 5
    5 6
    2 6
    
    예상 출력
    0 1 0 2 1 0
    
  2. 예제 2

    입력
    5 4
    1 2
    2 3
    3 4
    4 5
    
    예상 출력
    0 1 2 3 4