#P4467. [SCOI2007] k短路
[SCOI2007] k短路
Description
There are cities and directed roads, with cities numbered from to . Each road connects two different cities, and for any two roads, either their starting cities differ or their ending cities differ. Therefore, and satisfy .
Given two cities and , you can sort all simple paths (each city appears at most once, including the start and end) from to : first by total length in ascending order, and if lengths are equal, by lexicographical order in ascending order. Your task is to find the -th shortest path from to .
Input Format
The first line contains five positive integers .
Each of the following lines contains three integers , indicating there is a directed road from city to city with length .
Output Format
If there are fewer than simple paths from to , output No. Otherwise, output the -th shortest path: starting from city , output each visited city in order until city , separated by hyphens -.
5 20 10 1 5
1 2 1
1 3 2
1 4 1
1 5 3
2 1 1
2 3 1
2 4 2
2 5 2
3 1 1
3 2 2
3 4 1
3 5 1
4 1 1
4 2 1
4 3 1
4 5 2
5 1 1
5 2 1
5 3 1
5 4 1
1-2-4-3-5
4 6 1 1 4
2 4 2
1 3 2
1 2 1
1 4 3
2 3 1
3 4 1
1-2-3-4
3 3 5 1 3
1 2 1
2 3 1
1 3 1
No
Hint
In the first example, there are cities and all possible roads exist. There are simple paths from city to city , sorted as follows:

- 20% of the testdata: .
- 40% of the testdata: .
- 100% of the testdata: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号