The shortest path or the maximum Spanning Tree deformation.
Ask about the small weight that can be passed between two locations.
Use the shortest path to assign the initial value to INF, And the other value to 0. Then find dis [v] = min (DIS [u], d );
The spanning tree is to find the maximum spanning tree until the start and end points can communicate with each other, and the smallest side is.
Kruskal:
# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <cmath> # define INF 0x7fffffff # define EPS 1e-6 # define ll long longusing namespace STD; int n, m; int Fa [201]; Map <string, int> city; struct lx {int U, V, Len;} l [19901]; int father (int x) {If (X! = Fa [x]) return Fa [x] = Father (Fa [x]);} bool CMP (lx a, lx B) {return. len> B. len;} int main () {int nn = 1; while (scanf ("% d", & N, & M), N | m) {for (INT I = 0; I <= N; I ++) Fa [I] = I; city. clear (); char a [31], B [31]; int Len, U, V, COT = 0; For (INT I = 0; I <m; I ++) {scanf ("% S % d", a, B, & Len); U = City [a]; If (u = 0) city [a] = cot ++; u = City [a]; V = City [B]; If (V = 0) City [B] = cot ++; V = City [B]; L [I]. U = u, L [I]. V = V, L [I]. len = Len;} scanf ("% S % s", a, B); int x = City [a]; int y = City [B]; sort (L, L + M, CMP); int ans = inf; For (INT I = 0; I <m; I ++) {u = Father (L [I]. u); V = Father (L [I]. v); If (u = V) continue; Fa [v] = u; ans = min (ANS, L [I]. len); If (father (x) = Father (y) break;} printf ("Scenario # % d \ n % d tons \ n ", nn ++, ANS );}}
Poj 2263 heavy cargo (zoj 1952)