An undirected connected graph and edge weight are given. The objective is to find the path with the smallest edge weight in the path from one point to another. The output is the maximum edge weight of the path.
Because it is a path problem between two points, and the data size is small (only 100), we consider using the Floyd algorithm.
However, it does not require the shortest circuit between two points in the traditional Floyd request. However, by understanding the principle of the Floyd algorithm, we can find that the concept of Floyd can be used to solve this problem:
For any path I-> J that contains at least two edges, there must be an intermediate vertex K, make the total length of I-> J equal to the sum of I-> K and K-> J. Because there may be multiple paths, the minimum value must be obtained.
For any path I-> J that contains at least two edges, there must be an intermediate vertex K, so that the maximum values of I-> J are equal to the maximum values of I-> K and K-> J. Because there may be multiple paths, the minimum value must be obtained.
This is the above principle.
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define INF 0x3fffffff # define MEM (a) memset (A, 0, sizeof ()) int N, S, Q; int d [105] [105]; void Floyd () {for (int K = 1; k <= N; k ++) {for (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= N; j ++) {d [I] [J] = min (d [I] [J], max (d [I] [K], d [k] [J]) ;}}} int main () {// freopen ("out.txt", "W", stdout); int Kase = 1; while (scanf ("% d", & N, & S, & Q )! = EOF) {If (n = 0 & s = 0 & Q = 0) break; MEM (d); For (INT I = 0; I <= N; I ++) {for (Int J = 0; j <= N; j ++) d [I] [J] = inf;} int A1, a2, A3; For (INT I = 0; I <s; I ++) {scanf ("% d", & A1, & A2, & A3); D [a1] [a2] = A3; d [a2] [a1] = A3;} Floyd (); If (Kase! = 1) printf ("\ n"); printf ("case # % d \ n", Kase ++); For (INT I = 0; I <q; I ++) {int U, V; scanf ("% d", & U, & V); If (d [u] [v] = inf) printf ("no path \ n"); else printf ("% d \ n", d [u] [v]) ;}} return 0 ;}
Ultraviolet A 10048-audiophobia (Floyd deformation)