f-truckingTime
limit:3000MS
Memory Limit:0KB
64bit IO Format:%lld &%llu Submit Status
Description
A 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.
Input
The 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 byRLines each containing the city numbers of the cities connected by that road, the maximum height allowed on that 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 whenC=R= 0.
Output
For 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 Input
5 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 Output
case 1:maximum height = 7length of Shortest route = 20Case 2:maximum Height = 4length of Shortest route = 8Case 3:cannot reach destination
Test instructions: Lla gives you n nodes (<=1000), up to one path between nodes, path with length l and height limit h, Now a truck is ready to start from the beginning S to the end of T, requiring that the
truck's height must not be higher than H, asking the truck to reach the maximum height of the end point H and the shortest path at this maximum height;
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <vector > #include <queue> #include <cstring> #include <string> #include <algorithm>using namespace STD; #define MM (A, B) memset (A,b,sizeof (a)); #define INF 0x7f7f7f7fstruct edge{int to,h,l;}; vector<edge> g[1005];int dis[1005],inq[1005];bool ok (int s,int t,int h) {queue<int> q; MM (Dis,inf); MM (inq,0); Q.push (s); Inq[s]=1; dis[s]=0; while (Q.size ()) {int U=q.front (); Q.pop (); inq[u]=0; for (int i=0;i<g[u].size (); i++) {Edge e=g[u][i]; if (e.h
Analysis: The code is poisonous Ah,,, SPFA worst case v*e, supposedly should be card,,,,, or dijkstra+ heap optimization relatively stable;
Analysis: Very simple diagram thesis, to maximize a value of two points of course, the key is to find the road, in fact, is in the shortest way of code, plus a
The choice of path edge is that if the current path's height limit < binary enumeration is worth it, then this path is certainly not selectable (in fact, it is equivalent to
The original diagram of the limit height < The two-minute enumeration of H-side all erased), a simple pen, than the previously done diagram of the argument simply do not know where to go, the race
I'm scared to be silly.
LA 4223 Shortest path selection requires a little more