#include<iostream>
#define INF 999
using namespace std;
const int n=3;
void Floyd(int arc[n][n],int dist[n][n])
{
int i,j,k;
int path[9][3]={0};
for(i=0; i<n; i++) //初始化矩阵dist
{
for(j=0; j<n; j++)
{
dist[i][j]=arc[i][j];
}
}
for(k=0; k<n; k++)
{
int t=0;
for(i=0; i<n; i++) //n次迭代
{
for(j=0; j<n; j++)
{
if(dist[i][k]+dist[k][j] < dist[i][j])
{
dist[i][j]=dist[i][k]+dist[k][j];
path[t][k]=1;
}
t++;
}
}
}
printf("经过的路径点:\n a ");
printf(" b ");
printf(" c \n");
for(i=0; i<9; i++)
{
for(j=0; j<3; j++)
{
printf("-->%d ",path[i][j]);
}
printf("\n");
}
}
void display(int dist[n][n])
{
printf("最短路径权值:\n");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cout<<dist[i][j]<<" ";
cout<<endl;
}
}
int main(void)
{
int arc[n][n]={{0,4,11},{6,0,2},{3,INF,0}};
int dist[n][n]={{0,4,11},{6,0,2},{3,INF,0}};
int path[n^2][n]={0};
Floyd(arc,dist);
display(dist);
return 0;
}