Poj 3615 cow Hurdles

Source: Internet
Author: User
Cow Hurdles
Time limit:1000 ms   Memory limit:65536 K
Total submissions:5214   Accepted:2323

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.

Obviusly, 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 hasN(1 ≤N≤ 300) stations, conveniently labeled 1 ..N. A setM(1 ≤M≤ 25,000) one-way paths connects pairs of stations; the paths are also conveniently labeled 1 ..M. PathITravels
From stationSiTo StationEIAnd contains exactly one hurdle of heightHi(1 ≤Hi≤ 1,000,000). Cows must jump hurdles in any path they traverse.

The cows haveT(1 ≤T≤ 40,000) tasks to complete. TaskIComprises two distinct numbers,AIAndBi(1 ≤AIN; 1 ≤BiN), Which
Connote that a cow has to travel from StationAITo StationBi(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
FromAIToBi. Your job is to write a program that determines the path whose tallest hurdle is smallest and report that height.
 

Input

* Line 1: three space-separated integers:N,M, AndT
* Lines 2 ..M+ 1: LineI+ 1 contains three space-separated integers:Si,EI, AndHi 
* LinesM+ 2 ..M+T+ 1: LineI+M+ 1 contains two space-separated integers that describe task I:AIAndBi

Output

* Lines 1 ..T: LineIContains the result for taskIAnd tells the smallest possible maximum height necessary to travel between the stations. Output-1 if it is impossible to travel between the two stations.

Sample Input

5 6 31 2 123 2 81 3 52 5 33 4 42 4 83 41 25 1

Sample output

48-1

Source

Usaco 2007 November silver. . Find the minimum maximum height that a cow must jump
# Include <iostream> # include <stdio. h> using namespace STD; int INF = 100000000; int dis [350] [350]; int N; void Floyd () {int K, I, j; int T; for (k = 1; k <= N; k ++) for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) {T = dis [I] [k]> dis [k] [J]? Dis [I] [k]: DIS [k] [J]; // jump from I to K, then jump from K to a higher height of J. If (T <dis [I] [J]) // if conditions are met, update dis [I] [J] = T ;}} int main () {int M, T, I, J, S, E, H; scanf ("% d", & N, & M, & T); for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) {dis [I] [J] = dis [J] [I] = inf ;}for (I = 0; I <m; I ++) {scanf ("% d", & S, & E, & H); DIS [s] [e] = H;} Floyd (); while (t --) {scanf ("% d", & S, & E); printf ("% d \ n", DIS [s] [e]! = Inf? Dis [s] [e]:-1);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.