标签:
/* //hdu 2544 最短路 floyd
#include<stdio.h>
int main()
{
int e[201][201];
int inf=99999999;
int n,m;
int i,j,k;
int t1,t2,t3;
while(scanf("%d %d",&n,&m),n,m)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i==j) e[i][j]=0;
else e[i][j]=inf;
for(i=1;i<=m;i++)
{
scanf("%d %d %d",&t1,&t2,&t3);
if(e[t1][t2]>t3)
e[t2][t1]=e[t1][t2]=t3;//此步甚好
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(e[i][j]>e[i][k]+e[k][j] )
e[i][j]=e[i][k]+e[k][j];
printf("%d\n",e[1][n]<e[n][1] ? e[1][n]:e[n][1]);
}
return 0;
}
*/
/* hdu 2544 Dijkstra
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n,m,t1,t2,t3,e[201][201],book[201],dis[201],i,j,k,min,u,v;
int inf=99999999;
while(scanf("%d %d",&n,&m),n,m)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i == j) e[i][j]=0;
else e[i][j]=inf;
for(i=1;i<=m;i++)
{
cin>>t1>>t2>>t3;
if(e[t1][t2]>t3)
e[t1][t2]=e[t2][t1]=t3;
}
for(i=1;i<=n;i++)
dis[i]=e[1][i];
memset(book,0,sizeof(book));//这个初始化必须做好,不然wa还不易发现
book[1]=1;
for(i=1;i<=n-1;i++)
{
min=inf;
for(j=1;j<=n;j++)
{
if(book[j] == 0&&dis[j] < min)
{
min=dis[j];
u=j;
}
}
book[u]=1;
for(v=1;v<=n;v++)
{
if(e[u][v]<inf)
{
if(dis[v]>dis[u]+e[u][v])
dis[v]=dis[u]+e[u][v];
}
}
}
cout<<dis[n]<<endl;
}
return 0;
}
*/
标签:
原文地址:http://www.cnblogs.com/lmqpt/p/4701335.html