#5063. Problem 2. A Graph Problem
Problem 2. A Graph Problem
Problem 2. A Graph Problem
USACO 2023 December Contest, Platinum
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 .
- 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.
INPUT FORMAT (input arrives from the terminal / stdin):
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 FORMAT (print output to the terminal / stdout):
Output lines, where the th line should contain the return value of the process starting at vertex .
SAMPLE INPUT:
3 2 1 2 2 3
SAMPLE OUTPUT:
12 12 21
SAMPLE INPUT:
5 6 1 2 3 4 2 4 2 3 2 5 1 5
SAMPLE OUTPUT:
1325 1325 2315 2315 5132
Consider starting at . First, we choose edge , after which and . Second, we choose edge , after which and . Third, we choose edge , after which and . Finally, we choose edge , after which and . The answer for is therefore .
SAMPLE INPUT:
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
SAMPLE OUTPUT:
678925929 678925929 678862929 678787329 678709839 678632097 178554320 218476543 321398766 431520989 542453212 653475435 764507558 875540761 986574081
Make sure to output the answers modulo .
SCORING: Input 4: Inputs 5-6: Inputs 7-10: Inputs 11-14: for all Inputs 15-23: No additional constraints.
Problem credits: Benjamin Qi