标签:
http://acm.hdu.edu.cn/showproblem.php?pid=2544
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 100000000;
const int max_v = 110;
int d[max_v][max_v];
int e,v;
int main()
{
while(scanf("%d%d",&v,&e) && v) {
for(int i = 0 ; i < max_v ; i ++) {
for(int j = 0 ; j < max_v ; j ++) d[i][j] = INF;
}
for(int i = 0 ; i < max_v ; i ++) d[i][i] = 0;
while(e--) {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
d[a][b] = d[b][a] = c;
}
for(int k = 1 ; k <= v ; k ++) {
for(int i = 1 ; i <= v ; i ++) {
for(int j = 1 ; j <= v ; j ++) {
d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
}
}
}
printf("%d\n",d[1][v]);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/area_52/article/details/44114343