Folyd 算法模板
1 int dist[Max][Max], path[Max][Max], cost[Max][Max];
2 void Floyd(int n)
3 {
4 int i, j, k;
5 for (i=1; i<=n; i++)
6 for (j=1; j<=n; j++)
7 {
8 dist[i][j] = cost[i][j];
9 if(i!=j && dist[i][j]<Maxint)
10 path[i][j] = i;
11 else
12 path[i][j] = -1;
13 }
14 for (k=1; k<=n; k++)
15 {
16 for (i=1; i<=n; i++)
17 for (j=1; j<=n; j++)
18 {
19 if(dist[i][j] > dist[i][k]+dist[k][j])
20 {
21 dist[i][j] = dist[i][k] + dist[k][j];
22 path[i][j] = k;
23 }
24 }
25 }
26 }