A Graph Problem

시간 제한2초메모리 제한1024 MB

요약
각 시작 정점에서 현재 집합을 벗어나는 간선 중 번호가 가장 작은 것을 골라 추가할 때 만들어지는 수를 1e9+7로 나눈 나머지를 출력한다.
난이도

어려움10점 중 8점

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

문제

To improve her mathematical knowledge, Bessie has been taking a graph theory course and finds herself stumped by the following problem. Please help her!

You are given a connected, undirected graph with vertices labeled 1…N1\dots N and edges labeled 1…M1\dots M (2≤N≤2⋅1052\le N\le 2\cdot 10^5, N−1≤M≤4⋅105N-1\le M\le 4\cdot 10^5). For each vertex vv in the graph, the following process is conducted: ​

  1. Let S=vS=\\{v\\} and h=0h=0.

  2. While ∣S∣\<N|S|\<N, ​

    1. Out of all edges with exactly one endpoint in SS, let ee be the edge with the minimum label.
    2. Add the endpoint of ee not in SS to SS.
    3. Set h=10h+eh=10h+e.
  3. Return h(mod109+7)h\pmod{10^9+7}.

​ Determine all the return values of this process.

입력

The first line contains NN and MM. ​ Then follow MM lines, the eeth containing the endpoints (a_e,b_e)(a\_e,b\_e) of the eeth edge (1≤a_e\<b_e≤N1\le a\_e\<b\_e\le N). It is guaranteed that these edges form a connected graph, and at most one edge connects each pair of vertices.

출력

Output NN lines, where the iith line should contain the return value of the process starting at vertex ii.

예제3

  1. 예제 1

    입력
    3 2
    1 2
    2 3
    
    예상 출력
    12
    12
    21
    
  2. 예제 2

    입력
    5 6
    1 2
    3 4
    2 4
    2 3
    2 5
    1 5
    
    예상 출력
    1325
    1325
    2315
    2315
    5132
    
  3. 예제 3

    입력
    15 14
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 9
    9 10
    10 11
    11 12
    12 13
    13 14
    14 15
    
    예상 출력
    678925929
    678925929
    678862929
    678787329
    678709839
    678632097
    178554320
    218476543
    321398766
    431520989
    542453212
    653475435
    764507558
    875540761
    986574081