#P6628. [省选联考 2020 B 卷] 丁香之路

    ID: 7416 远端评测题 2000ms 512MiB 尝试: 1 已通过: 1 难度: 8 上传者: 标签>贪心2020并查集各省省选生成树欧拉回路

[省选联考 2020 B 卷] 丁香之路

Problem Description

As spring arrives and everything comes back to life, with the pandemic gradually ending, Yazid takes his nn good friends to visit the campus of University T. For convenience, we number them from 11 to nn.

The map of University T’s campus can be abstracted as an undirected graph with nn vertices (numbered from 11 to nn). For any two different vertices with indices i,ji, j (ij)(i \neq j), there is an undirected edge between them, and it takes ij|i - j| units of time to traverse.

Lilac is one of the symbolic flowers of University T. At present, lilacs are in bloom, and among the mm roads on campus, lilacs bloom on all of them. Yazid’s friends are very interested in lilacs, so they all want to traverse all of the mm roads where lilacs bloom.

Yazid’s friends start from vertex ss. The ii-th friend wants to end the visit at vertex ii. Meanwhile, as described above, each friend must traverse each of the mm roads with lilacs at least once.

Yazid’s friends do not want to get too tired, so they hope to spend as little time as possible to achieve their goals.

Please compute how many units of time each of Yazid’s friends needs to spend to complete their goal.

Input Format

The first line contains 33 non-negative integers n,m,sn, m, s. It is guaranteed that 1sn1 \le s \le n; and mn(n1)2m \le \frac {n(n-1)}2.

Lines 22 to m+1m+1 each contain 22 integers u,vu, v, describing an undirected edge with lilacs that connects vertices u,vu, v. It is guaranteed that 1u,vn1 \le u, v \le n and uvu \neq v; and each undirected edge is described at most once.

In every input line, multiple integers are separated by a single space.

Output Format

Output one line containing nn integers separated by a single space. The ii-th integer indicates the minimum time Yazid’s ii-th friend needs to complete the goal.

4 3 1
1 2
4 2
3 1
6 7 8 7
6 0 2
1 0 1 2 3 4
5 4 1
1 2
3 4
4 5
3 5
8 7 6 7 8

Hint

Sample Explanation 1

One optimal route for the 11-st friend is to start from 11, then go through 2,4,32, 4, 3 in order, and finally return to 11, costing 12+24+43+31=6|1-2|+|2-4|+|4-3|+|3-1| = 6 units of time.

One optimal route for the 22-nd friend is to start from 11, then go through 2,4,3,12, 4, 3, 1 in order, and finally arrive at 22, costing 77 units of time.

One optimal route for the 33-rd friend is to start from 11, then go through 2,4,12, 4, 1 in order, and finally arrive at 33, costing 88 units of time.

One optimal route for the 44-th friend is to start from 11, then go through 3,1,23, 1, 2 in order, and finally arrive at 44, costing 77 units of time.

Sample Explanation 2

Since m=0m = 0, there are no mandatory roads, so each friend can go directly to the destination via a single edge.

Constraints and Notes

Test Point ID n=n = Other Special Constraints
131\sim 3 5050 m=9m = 9
464\sim 6 m=15m = 15
787\sim 8
9109\sim 10 300300
1111 16001600 m=0m = 0
121412\sim 14 m=1m = 1
151715\sim 17
182018\sim 20 25002500

Translated by ChatGPT 5