A Graph Problem
시간 제한2초메모리 제한1024 MB
각 시작 정점에서 현재 집합을 벗어나는 간선 중 번호가 가장 작은 것을 골라 추가할 때 만들어지는 수를 1e9+7로 나눈 나머지를 출력한다.
문제
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 and edges labeled (, ). For each vertex in the graph, the following process is conducted:
-
Let and .
-
While ,
- Out of all edges with exactly one endpoint in , let be the edge with the minimum label.
- Add the endpoint of not in to .
- Set .
-
Return .
Determine all the return values of this process.
입력
The first line contains and . Then follow lines, the th containing the endpoints of the th edge (). It is guaranteed that these edges form a connected graph, and at most one edge connects each pair of vertices.
출력
Output lines, where the th line should contain the return value of the process starting at vertex .