Beginning to know that the Floyd algorithm is in the "Big talk Data Structure" this book of the non-oriented map to find the shortest path to see,
But the first time did not understand, so I did not read, and then looked at two times still did not understand, I think I understand the ability to have a problem
Later from the Baidu Encyclopedia read again, once understood, is actually dynamic planning
State transition Equation d[i][j] = min (D[i][k] + d[k][j], d[i][j])
The shortest path from I to J is obtained by the state transfer equation
#include <stdio.h> #include <stdlib.h> #define INF 1 << 30int d[1000][1000];int Main () {int I, j, K, M, n;// M represents the number of sides, N is the number of vertices int x, y, z;scanf ("%d%d", &n, &m);//weight initialization for (i = 0; i < n; i++) for (j = 0; J < N; j + +) D[i][j] = Establishment of inf;//adjacency matrix for (i = 0; i < m; i++) {scanf ("%d%d%d", &x, &y, &z);d [x][y] = z;d[y][x] = z;} for (k = 0, k < n; k++) for (i = 0, i < n; i++) for (j = 0; J < N; j + +) {if (D[i][k] + d[k][j]<d[i][j]) d[i][j] = D[I][K] + d[k][j];} for (i = 0; i < n; i++) {for (j = 0; J < N; j + +) printf ("%d", D[i][j]);p UTS (""); return 0;}
Floyd algorithm Explanation