Consider the map of a country, with cities (numbered between and ) and unidirectional roads that connect them. Each road has a certain length. We want to go from city to city . As we travel with people prone to get carsick, and we do not want to stop halfway to stretch our legs, we want to follow the route such that the longest road we take is as short as possible. That is, if the route uses roads, with lengths , , , and , we want to be as small as possible.
The input consists in several cases. Each case begins with and , followed by triplets , with , indicating a road that goes from to of length . Assume , , that there is at most one road from to in this order, that the lengths are between 1 and , and that there is always a route between 0 and 1.
For each case, write the maximum length of the roads of the best possible route.
The second line of the example of output corresponds to the route , which has a road (the ) of maximum length 80.
Consider a variant of Dijkstra’s algorithm.
Input
2 2 0 1 100000 1 0 42 5 6 0 1 90 0 4 80 4 1 60 0 2 100 2 1 60 4 2 70
Output
100000 80