Topic Source HDU 2962 Trucking
Test instructions: give you a graph n point M Edge gives the starting point S end e and the maximum withstand height where each road has a limit of height and the length of the road to the maximum can pass from S to e height and the maximum height of the premise of the shortest path
Train of thought: two-point height to find the shortest circuit without a special sentence
#include <cstdio> #include <algorithm> #include <queue> #include <vector> using namespace std;
const int MAXN = 1010;
struct Edge {int u, V, H, W;};
struct Heapnode {int u, D;
BOOL operator < (const heapnode& RHS) Const {return d > rhs.d;
}
};
Vector <edge> G[MAXN];
int DIS[MAXN];
BOOL VIS[MAXN];
int n, m;
int S, E;
void Dijkstra (int h) {for (int i = 0; I <= N; i++) dis[i] = 999999999;
memset (DIS, 0x7f, sizeof (DIS));
Dis[s] = 0;
Memset (Vis, false, sizeof (VIS));
Priority_queue <HeapNode> Q;
Q.push ((Heapnode) {s, 0}); while (!
Q.empty ()) {Heapnode x = Q.top ();
Q.pop ();
int u = x.u;
if (Vis[u]) continue;
Vis[u] = true;
for (int i = 0; i < g[u].size (); i++) {Edge e = g[u][i];
if (E.h < h) continue;
int v = e.v;
if (Dis[v] > x.d + e.w) {Dis[v] = x.d + e.w;
Q.push ((Heapnode) {V, dis[v]});
}}}} int main () {int cas = 0; while (scanf ("%d%d", &n, &m) && (N+m)) {for (int i = 0; I <= N; i++) g[i].clear ();
for (int i = 0; i < m; i++) {int u, V, H, W;
scanf ("%d%d%d", &u, &v, &h, &w);
if (h = =-1) h = 999999999;
G[u].push_back (Edge) {u, V, h, w});
G[v].push_back (Edge) {V, U, h, w});
} int lim;
scanf ("%d%d%d", &s, &e, &lim);
int L = 0, r = Lim, ans =-1, Len;
while (L <= r) {int mid = (L + r) >> 1;
Dijkstra (mid);
if (dis[e]! = 999999999) {ans = mid;
len = Dis[e];
L = mid + 1;
} else {r = mid-1;
}} if (cas++) puts ("");
printf ("Case%d:\n", CAs);
if (ans = =-1) {puts ("Cannot reach destination");
Continue
} printf ("Maximum height =%d\n", ans);
printf ("Length of shortest route =%d\n", Len);
} return 0; }