#P6037. Ryoku 的探索
Ryoku 的探索
Description
Ryoku’s world can be modeled as a weighted, undirected, connected graph with vertices and edges. Each edge has a beauty value and a length.
Ryoku explores the world using the following strategy: at each vertex, among the edges whose endpoint she has not visited yet, she chooses the one with the highest beauty value to walk along. If there is no edge to take, she returns along the edge she used to reach this vertex, similar to a graph depth-first traversal.
The length of an exploration plan is the sum of the lengths of all edges that the plan walks through (the distance walked when returning does not need to be counted).
She wants to know, for every starting vertex , what total length she needs to walk.
Input Format
The input contains lines. The first line contains an integer .
The next lines each contain four integers , describing an undirected edge connecting and , with length and beauty value .
Output Format
Output lines, each containing one integer. The -th line is the answer when .
5
4 1 2 1
1 2 3 2
3 1 1 4
3 5 2 5
2 3 2 3
7
7
8
7
8
Hint
[Sample 1 Explanation]
The following is the graph in Sample Input/Output 1 (the red numbers on edges are , and the black numbers are ).

If the starting point is , the order is , and the sum of lengths is .
If the starting point is , the order is , and the sum of lengths is .
If the starting point is , the order is , and the sum of lengths is .
If the starting point is , the order is , and the sum of lengths is .
If the starting point is , the order is , and the sum of lengths is .
[Constraints]
For of the testdata, .
For of the testdata, , , . It is guaranteed that all are distinct.
Translated by ChatGPT 5
京公网安备 11011102002149号