#P6037. Ryoku 的探索

    ID: 4545 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2020深度优先搜索,DFS环套树,基环树

Ryoku 的探索

Description

Ryoku’s world can be modeled as a weighted, undirected, connected graph GG with nn vertices and nn 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 s=1,2,,ns=1,2,\cdots,n, what total length she needs to walk.

Input Format

The input contains n+1n+1 lines. The first line contains an integer nn.
The next nn lines each contain four integers u,v,w,pu,v,w,p, describing an undirected edge connecting uu and vv, with length ww and beauty value pp.

Output Format

Output nn lines, each containing one integer. The ii-th line is the answer when s=is=i.

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 pp, and the black numbers are ww).

If the starting point is 11, the order is 135241\to3\to5\to2\to4, and the sum of lengths is 77.
If the starting point is 22, the order is 235142\to3\to5\to1\to4, and the sum of lengths is 77.
If the starting point is 33, the order is 351243\to5\to1\to2\to4, and the sum of lengths is 88.
If the starting point is 44, the order is 413524\to1\to3\to5\to2, and the sum of lengths is 77.
If the starting point is 55, the order is 531245\to3\to1\to2\to4, and the sum of lengths is 88.


[Constraints]

For 40%40\% of the testdata, n103n\le 10^3.
For 100%100\% of the testdata, 3n1063 \le n \le 10^6, 1u,v,pn1 \le u,v,p \le n, 0w1090\le w\le 10^9. It is guaranteed that all pp are distinct.

Translated by ChatGPT 5