Cow Hurdles
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 6486 |
|
Accepted: 2948 |
Description
Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang is practicing jumping ov ER hurdles. They is getting tired, though, so they want to being able to use as little energy as possible to jump over the hurdles.
Obviously, it isn't very difficult for a cow to jump over several very short hurdles, but one tall hurdle can be very str Essful. Thus, the cows is only concerned about the height of the tallest hurdle they has to jump over.
The cows ' practice-has n (1≤ n ≤300) stations, conveniently labeled 1..< Em>n . A set of m (1≤ m ≤25,000) one-way paths connects pairs of stations; The paths is also conveniently labeled 1. M . path i travels from station Si to station Ei and contains exactly one hurdle of height Hi (1≤ hi ≤1,000,000). Cows must jump hurdles on any path they traverse.
The cows has T (1≤ T ≤40,000) tasks to complete. Task I comprises the distinct numbers, ai and Bi (1≤ ai ≤ N; 1≤ Bi ≤ N), which connote that a cow have to travel from station Ai to station Bi (by traversing OV Er 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 AI to Bi . Your job is-to-write a program, determines the path whose tallest hurdle is smallest and report that height.
Input
* Line 1:three space-separated integers: N, M, and T
* Lines 2. M+1:line i+1 contains three space-separated integers: Si , Ei , and Hi
* Lines M+2.. m+T+1:line i+m+1 contains II space-separated integers that describe task I: C13>ai and Bi
Output
* Lines 1. T: Line i contains the result for task I and tells the smallest possible maximum height n Ecessary to travel between the stations. Output-1 if it is impossible to travel between the 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 November Silver naked delivery closures ah ah. Drunk ... Do not say. I want to be quiet.
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMAXN =305;intDIS[MAXN][MAXN];intN;intm;intT;intMain () {memset (DIS,0x7f,sizeof(DIS)); scanf ("%d%d%d", &n, &m, &t); for(inti =0; I < m; ++i) {intu; intv; intW; scanf ("%d%d%d", &u, &v, &W); DIS[U][V]=min (Dis[u][v], W); } for(intK =1; K <= N; ++k) for(inti =1; I <= N; ++i)if(k! =i) for(intj =1; J <= N; ++j)if(k! = J && I! = j) Dis[i][j] =min (dis[i][j], Max (Dis[i][k], dis[k][j])); while(t--) { intu; intv; scanf ("%d%d", &u, &v); if(Dis[u][v] >1000000) printf ("-1\n"); Elseprintf"%d\n", Dis[u][v]); } return 0;}
"POJ 3615" Cow hurdles