动态规划思想的Flord
#include<iostream>
using namespace std;
int d[5000][5000];
int main()
{
int i,j,n,m,u,v,w,k;
cin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
d[i][j]=2147483647;
}
for (i=1;i<=m;i++)
{
cin>>u>>v>>w;
d[u][v]=w;
d[v][u]=w;
}
for (k=1;i<=n;i++)
for (i=1;j<=n;j++)
for (j=1;k<=n;k++)
{
if(d[i][k]!=2147483647&&d[k][j]!=2147483647&&d[i][j]>d[i][k]+d[k][j])
d[i][j]=d[i][k]+d[k][j];
}
}
图论4——多源最短路径
原文:https://www.cnblogs.com/idyllic/p/10827788.html