hdu2544
#include<cstdio>
using namespace std;
const int N=105;
const int INF=1e5+5;
int n,m,u,v,c,map[N][N];
void floyd(){
for(int k=1;k<=n;k++ ){
for(int i=1;i<=n;i++){
if(map[i][k]!=INF){
for(int j=1;j<=n;j++){
if(map[i][j]>map[i][k]+map[k][j]){
map[i][j]=map[i][k]+map[k][j];
}
}
}
}
}
printf("%d\n",map[1][n]);
}
int main(){
while(scanf("%d%d",&n,&m),n){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
map[i][j]=INF;
}
}
for(int i=1;i<=m;i++){
scanf("%d%d%d",&u,&v,&c);
map[u][v]=map[v][u]=c;
}
floyd();
}
return 0;
}
来源:CSDN
作者:later_koki
链接:https://blog.csdn.net/later_koki/article/details/104443592