#P3597. [POI 2015 R3] 旅行 Trips
[POI 2015 R3] 旅行 Trips
Description
Given a weighted directed graph with vertices and edges, where each edge weight is one of , , or .
Sort all possible paths by their total length and output the length of the -th shortest path. Note that a path does not have to be simple; the same vertex may be visited multiple times.
Input Format
The first line contains three integers (, , ).
Each of the next lines contains three integers (, , ), indicating there is a directed edge from to with length .
Parallel edges may exist.
Output Format
Output a single positive integer: the length of the -th shortest path. If it does not exist, output .
6 6 11
1 2 1
2 3 2
3 4 2
4 5 1
5 3 1
4 6 3
4
Hint
Sample explanation:
Paths of length : , , . Paths of length : , , . Paths of length : , , , . Paths of length : .
Original title: Wycieczki.
Translated by ChatGPT 5
京公网安备 11011102002149号