A toll-road network connects n towns, numbered 0 to n - 1, with m two-way roads.
Road i connects towns u and v and charges a toll of w to use. A driver cares about the single
WORST (highest) toll paid on their route, since that is the most they will ever be charged at one
booth.
Given a starting town s and a destination town t (with s != t), print the smallest possible value
of the worst toll along any route from s to t (i.e., choose the route that minimizes its own
maximum toll). If t is unreachable from s, print -1 instead.
Input format
Line 1: two integers n m.
Next m lines: three integers u v w -- an undirected road between towns u and v with toll w
(towns are 0-indexed).
Last line: two integers s t.
Output format
A single integer: the minimum possible value of the worst toll along a route from s to t, or -1
if unreachable.
Constraints
- 2 <= n <= 1000
- 0 <= m <= 4000
- 0 <= u, v < n, u != v
- 1 <= w <= 1000000
- 0 <= s, t < n, s != t