luogu#P2888. [USACO07NOV] Cow Hurdles S
[USACO07NOV] Cow Hurdles S
题目描述
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.
Farmer John 想让她的奶牛准备郡级跳跃比赛,Bessie 和她的伙伴们正在练习跨栏。她们很累,所以她们想消耗最少的能量来跨栏。 显然,对于一头奶牛跳过几个矮栏是很容易的,但是高栏却很难。于是,奶牛们总是关心路径上最高的栏的高度。
奶牛的训练场中有 个站台,分别标记为 。所有站台之间有 条单向路径,第 条路经是从站台 开始,到站台 ,其中最高的栏的高度为 。无论如何跑,奶牛们都要跨栏。
奶牛们有 个训练任务要完成。第 个任务包含两个数字 和 ,表示奶牛必须从站台 跑到站台 ,可以路过别的站台。奶牛们想找一条路径从站台 到站台 ,使路径上最高的栏的高度最小。 你的任务就是写一个程序,计算出路径上最高的栏的高度的最小值。
输入格式
* 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
第一行:三个空格隔开的整数 。
接下来 行:第 行包含三个空格隔开的整数 。
接下来 行:第 行包含两个空格隔开的整数,表示任务 的起始站台和目标站台 。
输出格式
* 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.
行:第 行为一个整数,表示任务 路径上最高的栏的高度的最小值。如果无法到达,输出 -1
。
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
提示
对于 的数据,,,,,。
感谢 @gaozhiyong @Cppsteve 提供翻译