#P2888. [USACO07NOV] Cow Hurdles S
[USACO07NOV] Cow Hurdles S
Description
Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over the hurdles.
Obviously, it is not very difficult for a cow to jump over several very short hurdles, but one tall hurdle can be very stressful. Thus, the cows are only concerned about the height of the tallest hurdle they have to jump over.
The cows' practice room has stations, conveniently labeled . A set of one-way paths connects pairs of stations; the paths are also conveniently labeled . Path travels from station to station and contains exactly one hurdle of height . Cows must jump hurdles in any path they traverse.
The cows have tasks to complete. Task comprises two distinct numbers, and , which connote that a cow has to travel from station to station (by traversing over one or more paths over some route). The cows want to take a path the minimizes the height of the tallest hurdle they jump over when traveling from to . Your job is to write a program that determines the path whose tallest hurdle is smallest and report that height.
Input Format
* Line : Three space-separated integers: , , and
* Lines : Line contains three space-separated integers: , , and
* Lines : Line contains two space-separated integers that describe task : and
Output Format
* Lines : Line contains the result for task and tells the smallest possible maximum height necessary to travel between the stations. Output -1 if it is impossible to travel between the two stations.
5 6 3
1 2 12
3 2 8
1 3 5
2 5 3
3 4 4
2 4 8
3 4
1 2
5 1
4
8
-1
京公网安备 11011102002149号