#BS0000433. Đường đi có cạnh lớn nhất nhỏ nhất (Minimum maximum on the Path)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường đi có cạnh lớn nhất nhỏ nhất (Minimum maximum on the Path)
Minimum maximum on the Path
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A road network consists of intersections numbered from to and one-way roads. Each road goes from an intersection with a smaller number to one with a larger number and has a nonnegative integer weight.
You must travel from intersection to intersection using at most roads. The value of a path is the largest weight among the roads it uses.
Find a valid path of minimum value. If several paths have the same minimum value, output any of them. If intersection cannot be reached within the road limit, output -1.
Input
The first line contains three integers : the number of intersections, the number of roads, and the maximum number of roads allowed on the path.
Each of the next lines contains three integers , describing a one-way road from intersection to intersection with weight .
Output
If no valid path exists, output only -1.
Otherwise, print an integer , the number of roads used, on the first line. On the second line, print integers representing the intersections in traversal order, beginning with and ending with . The path must satisfy and have the minimum possible value.
Subtasks
-
Subtask 1 (20 points): , , , , for every ; no two roads have the same ordered pair of endpoints.
-
Subtask 2 (30 points): , , , , for every ; no two roads have the same ordered pair of endpoints.
-
Subtask 3 (50 points): , , , , for every ; no two roads have the same ordered pair of endpoints.
Examples
Input
4 5 2
1 2 5
2 3 3
1 3 7
2 4 6
3 4 4
Output
2
1 2 4
Explanation
There are two paths using at most two roads: has value , while has value . The path has value but uses three roads, exceeding . Thus the minimum feasible value is , attained by the two-road path through intersection .