- void shortpath_FLOYD(int cost[][M],int path[][M],int length[][M],int n)
- { int i,j,k,wm;
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- { length[i][j]=cost[i][j];
- if(i==j) path[i][j]=0;
- else if(length[i][j]<MAX)
- path[i][j]=i+1;
- else path[i][j]=0;
- }
- for(k=0;k<n;k++)
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- if(length[i][k]+length[k][j]<length[i][j])
- { length[i][j]=length[i][k]+length[k][j];
- path[i][j]=path[k][j];
- }
- }