Trucking
problem DescriptionA certain local trucking company would such as transport some goods on a cargo truck from one place to another. It is desirable to transport as much goods as possible each trip. Unfortunately, one cannot always use the roads in the shortest route:some roads may have obstacles (e.g. bridge overpass, Tunnels) which limit heights of the goods transported. Therefore, the company would such as transport as much as possible each trip, and then choose the shortest route that can be used to transport that amount.
For the given cargo truck, maximizing the height of the goods transported are equivalent to maximizing the amount of goods Transported. For safety reasons, there are a certain height limit for the cargo truck which cannot be exceeded.
InputThe input consists of a number of cases. Each case is starts with the integers, separated by a space, and on a line. These integers is the number of cities (C) and the number of roads (R). There is at most of cities, numbered from 1. This was followed by R lines each containing the city numbers of the cities connected by that road, the maximum height allo Wed on this road, and the length of that road. The maximum height for each road are a positive integer, except that a height of-1 indicates this there is no height limit On that road. The length of each road was a positive integer at most 1000. Every road can be travelled in both directions, and there are at the most one road connecting each distinct pair of cities. Finally, the last line of all case consists of the start and end city numbers, as well as the height limit (a positive in Teger) of the cargo truck. The input terminates when C = R = 0.
OutputFor each case, print the case number followed by the maximum height of the cargo truck allowed and the length of the EST route. Use the format as shown in the sample output. If It isn't possible to reach the end city from the start city, print "Cannot reach destination" after the case number. Print a blank line between the output of the cases.
Sample Input5 61 2 7 51 3 4 22 4-1 102 5 2 43 4 10 14 5 8 51 5 105 61 2 7 51 3 4 22 4-1 102 5 2 43 4 10 14 5 8 51 5 43 11 2-1 1001 3 100 0
Sample OutputCase 1:maximum height = 7length of Shortest route = 20Case 2:maximum height = 4length of Shortest route = 8Case 3:cannot R Each destination
Test Instructions:Given an no-show graph, each road has a limit on the height of the truck. The highest height of the truck from the starting point to the end point and the shortest path to travelThe
following:We are two points high, at this height to the shortest possible, to resolve whether to reach the end point, if you can record the length of the path to update the answer
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespacestd; typedefLong Longll;Const intN =2000000+Ten;Const intINF = 1e9 +7;intdis[n],head[n],vis[n],t,n,m,t;structss{intTo,h,v,next;} E[n];voidAddintUintVintHintW) {e[t].to=v; E[t].next=Head[u]; E[T].V=W; E[t].h=h; Head[u]= t++;}intSPFA (intXintLIMT) {Queue<int>Q; for(inti =0; I <= N; i++) Dis[i] = inf, vis[i] =0; DIS[X]=0; Q.push (x); VIS[X]=1; while(!Q.empty ()) { intK =Q.front (); Q.pop (); Vis[k]=0; for(inti = head[k]; I i =E[i].next) { if(E[i].h < LIMT)Continue; if(Dis[e[i].to] > Dis[k] +e[i].v) {Dis[e[i].to]= Dis[k] +e[i].v; if(!Vis[e[i].to]) {Vis[e[i].to]=1; Q.push (e[i].to); } } } } returndis[t];}intMain () {intA,b,h,v,s,cas =1; while(~SCANF ("%d%d",&n,&m)) {if(!n | |!m) Break; if(CAs >1) printf ("\ n"); T=1; Memset (Head,0,sizeof(head)); for(inti =1; I <= m; i++) {scanf ("%d%d%d%d",&a,&b,&h,&v); if(H = =-1) H =inf; Add (A,B,H,V); Add (B,A,H,V); } scanf ("%d%d%d",&s,&t,&h); intL =0, r = h, ans =inf; while(L <r) {intMid = (L + R +1) >>1; if(SPFA (S,MID)! = inf) L = Mid, ans =Dis[t]; ElseR = Mid-1; } printf ("Case %d:\n", cas++); if(ans = inf) printf ("Maximum height =%d\nlength of Shortest route =%d\n", L, ans); Else{printf ("cannot reach destination\n"); } } return 0;}
Uvalive 4223/hdu 2962 SPFA + two minutes