luogu#P2832. 行路难【疑似 std 复杂度有误】
行路难【疑似 std 复杂度有误】
Background
Xiao X came to the mountains and enjoyed the pleasures of the forest. While he was happily forgetting his worries, he suddenly realized that the new semester was imminent.
Problem Description
There are mountains in the mountainous area. There are narrow mountain paths between the mountains. Each path connects two mountains, is one-way, and costs Xiao X a certain amount of time.
Xiao X is currently at mountain . His goal is mountain , because there is a train station there.
However, Xiao X’s stamina is limited. Each time he traverses a narrow mountain path, he becomes more tired, causing the time to traverse any narrow mountain path to increase by .
Input Format
The first line contains two integers, .
From line to line , each line contains integers , indicating that there is a narrow mountain path from to that allows Xiao X to move from to with a time cost of .
Output Format
The first line contains an integer , the shortest time Xiao X needs.
The second line contains a sequence of integers separated by spaces, representing Xiao X’s route. For example, [1, 4, 2, 5] means Xiao X starts from mountain 1, moves to mountain 4, then to mountain 2, and finally to mountain 5.
5 8
2 4 2
5 2 1
1 2 1
4 3 2
1 3 3
4 5 2
1 5 8
3 5 3
7
1 3 5
Hint
Constraints
For all testdata, , .
The testdata guarantees that the shortest path is unique.
Translated by ChatGPT 5