Flody
For (k = 0; k <n; k ++) // intermediate node
For (I = 0; I <n; I ++) // start point
For (j = 0; j <n; j ++) // key
Map [I] [j] = min (map [I] [j], map [I] [k] + map [k] [j]);
For example, HDU2544
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace std; const int INF = 99999; const int maxn = 105; int N, M; int d [maxn]; int map [maxn] [maxn]; int main (void) {int I, j, k, A, B, C; while (scanf ("% d ", & N, & M) = 2) {if (N = 0 & M = 0) break; for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) map [I] [j] = INF; for (I = 1; I <= M; I ++) {scanf ("% d", & A, & B, & C); if (map [A] [B]> C) map [A] [B] = map [B] [A] = C;} for (k = 1; k <= N; k ++) // intermediate node for (I = 1; I <= N; I ++) // start point for (j = 1; j <= N; j ++) // Key map [I] [j] = min (map [I] [j], map [I] [k] + map [k] [j]); printf ("% d \ n", map [1] [N]);} return 0 ;}