标签:des style color java os io strong 数据
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 32036 Accepted Submission(s): 13893
2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0
3 2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int Road[110][110],n, fz[110];
struct node
{
int s,l;
};
int dfs()
{
int min1=1000000;
memset(fz,0,sizeof fz);
node a,b;
a.s=1;
a.l=0;
fz[1]=0;
queue<node>q;
q.push(a);
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=2;i<=n;i++)
{
b.s=i;
b.l=a.l+Road[a.s][i];
if(Road[a.s][i]!=0&&(fz[i]==0||fz[i]>b.l))
{
fz[i]=b.l;
if(b.s==n&&min1>b.l)
{
min1=b.l;
}
q.push(b);
}
}
}
return min1;
}
int main()
{
int m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,a,b,c;
if(n==0&&m==0)break;
memset(Road,0,sizeof Road);
for(i=0;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
Road[a][b]=c;
Road[b][a]=c;
}
printf("%d\n",dfs());
}
return 0;
}
标签:des style color java os io strong 数据
原文地址:http://blog.csdn.net/fljssj/article/details/38518411