Test instructions: The shortest way under the maximum height, because the topic gives the limit high, so we only need two points height and then use SPFA
#include <iostream> #include <string.h> #include <queue> #include <vector> #include <utility > #include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define N 205#define MAXN 2005const int INF = 9999999;int ht[maxn][maxn];int mp[maxn][maxn];int d[maxn];int mid_ht;int n,m;int used[maxn];void SPFA (int s) {fill (d,d+n+1,inf); Queue<int> que; Fill (used,used+n+1,0); D[s] = 0; Que.push (s); while (!que.empty ()) {int u = que.front (); Que.pop (); Used[u] = 0; for (int i = 1; I <= n; i++) {if (Ht[u][i] >= mid_ht && ht[u][i]| | ht[u][i] = = 1) {if (D[i] > D[u] + mp[u][i]) {d[i] = D[u] + mp[u][i]; if (!used[i]) {used[i] = 1; Que.push (i); }}}}}}int main () {#ifdef XXZ freopen ("In.txt", "R", stdin); #endif//XXZ int a,b,c,e; int case = 1; while (~SCANF ("%d%d", &n,&m)) {if (n = = 0 && m== 0) break; for (int i = 0; I <= N; i++) {fill (mp[i],mp[i]+n+1,inf); Fill (ht[i],ht[i]+n+1,0); } for (int i = 0; i < m; i++) {scanf ("%d%d%d%d", &a,&b,&c,&e); MP[A][B] = mp[b][a] = e; HT[A][B] = ht[b][a] = C; } int start,end,h; scanf ("%d%d%d", &start,&end,&h); int L = 0, r = h; int ans = 0, ans2 = INF; while (L <= r) {mid_ht = (l+r)/2; SPFA (start); if (d[end] = = INF) {r = mid_ht-1; } else {if (ans < mid_ht) {ans = mid_ht; Ans2 = D[end]; } else if (ans = = Mid_ht && D[end] &lT ANS2)//Pay attention to this item when the height is considered at the same time as the smaller path {ans2 = D[end]; } L = mid_ht+1; }} if (case >1) printf ("\ n");//otherwise PE printf ("Case%d:\n", case++); if (ans2 = = INF | | ans = = 0) {printf ("Cannot reach destination\n"); } else {printf ("Maximum height =%d\n", ans); printf ("Length of shortest route =%d\n", ans2); }} return 0;}
hdu2962 (Shortest circuit + two points)