#P2829. 大逃离
大逃离
Description
This is a graph with nodes and undirected edges. Each edge has a length of units. zrz is at position , and the exit is at position .
However, zrz’s brain has a little bug: he does not want the shortest path; he wants the second-shortest path. The second-shortest path may share edges with the shortest path and may pass through some nodes and edges multiple times. Note that if there are multiple paths that are all shortest, none of them can be called the second-shortest path.
In addition, if the next node to enter has fewer than directly connected neighbors (excluding the start and the exit), then zrz will not dare to enter it.
Input Format
The first line contains three numbers: .
The next lines each contain three numbers , indicating there is an undirected edge of weight between and .
Output Format
Output a single number: the length of the second-shortest path from to . If it does not exist, output .
4 4 1
1 2 100
2 4 200
2 3 250
3 4 100
450
4 4 3
1 2 100
2 4 200
2 3 250
3 4 100
500
Hint
Constraints:
- For of the testdata: , .
- For of the testdata: , .
- For of the testdata: , , , .
Also, is relatively small.
In Sample , the shortest path is (1-2-4). Because it is impossible to go from to ( is connected to only nodes), it is allowed to go 1-2-1-2-4, and the second-shortest path is .
Translated by ChatGPT 5
京公网安备 11011102002149号