10261: CF EDU - Binary Search - Step 3 - D. Minimum maximum on the Path
[Creator : ]
Description
The road network consists of $n$ junctions and $m$ one-way roads, with each road leading from a lower-numbered junction to a higher-numbered junction. Each road has a number. Your task is to find a path from junction $1$ to junction $n$, consisting of at most $d$ edges, on which the maximum of the numbers corresponding to the edges is minimal possible.
Input
The first line contains integers $n, m, d\ (2≤n≤10^5,\ 1≤m,d≤10^5)$.
The next $m$ lines contain triples of numbers $a_i, b_i, c_i\ (1≤a_i<b_i≤n,\ 0≤c_i≤10^9)$, which mean that there is a road, leading from the junction $a_i$ to the junction $b_i$, which has number $c_i$. For each pair of junctions, there is at most one road that connects them.
Output
On the first line print the number of edges in the selected path $k\ (k≤d)$.
On the next line print $k+1$ integers, indices of junctions visited by the selected path.
If there is no path from junction $1$ to junction $n$ consisting of at most $d$ edges, print one integer $-1$.
Sample 1 Input
4 5 2
1 2 5
2 3 3
1 3 7
2 4 6
3 4 4
Sample 1 Output
2
1 2 4
Sample 2 Input
3 3 2
1 2 1
2 3 2
1 3 1
Sample 2 Output
1
1 3
Sample 3 Input
3 2 1
1 2 1
2 3 1
Sample 3 Output
-1