http://acm.hdu.edu.cn/showproblem.php?pid=2544
继续研究,dijkstra 和 bellmanford 算法
#include<iostream>
int main()
{
int n,m,a,b,c;
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF&&(n||m))
{
int maze[101][101]={0};
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
maze[a][b]=c;
maze[b][a]=c;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(maze[k][j]&&maze[i][k]&&(maze[i][j]>maze[i][k]+maze[k][j]||maze[i][j]==0))
maze[i][j]=maze[i][k]+maze[k][j];
}
printf("%d\n",maze[1][n]);
}
return 0;
}