标签:des style color java os io strong for
3 2 1 2 5 6 2 3 4 5 1 3 0 0
9 11
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MX=1<<30;
int Road[1100][1100][2],n,fz[1100][2];
int s,e;
struct node
{
int s,l,fee;
};
void dfs(int &l,int &fee)
{
node a,b;
a.s=s;
a.l=0;
a.fee=0;
l=fee=MX;
fz[a.s][0]=0;
fz[a.s][1]=1;
queue<node>q;
q.push(a);
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=1;i<=n;i++)
{
b.s=i;
b.l=a.l+Road[a.s][i][0];
b.fee=a.fee+Road[a.s][i][1];
if(Road[a.s][i][0]!=MX&&
(fz[i][0]>b.l||(fz[i][0]==b.l&&fz[i][1]>b.fee)))
{
fz[i][0]=b.l;
fz[i][1]=b.fee;
if(b.s==e&&(l>b.l||(l==b.l&&fee>b.fee)))
{
l=b.l;
fee=b.fee;
}
q.push(b);
}
}
}
}
int main()
{
int m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j,a,b,c,d;
if(n==0&&m==0)break;
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
Road[i][j][0]=MX;
Road[i][j][1]=MX;
}
fz[i][0]=MX;
fz[i][1]=MX;
}//初始化
for(i=0;i<m;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(c<Road[a][b][0]||(c==Road[a][b][0]&&Road[a][b][1]>d)){
Road[a][b][0]=c;
Road[b][a][0]=c;
Road[a][b][1]=d;
Road[b][a][1]=d;}
}
scanf("%d%d",&s,&e);
int l,fee;
dfs(l,fee);
printf("%d %d\n",l,fee);
}
return 0;
}
标签:des style color java os io strong for
原文地址:http://blog.csdn.net/fljssj/article/details/38518359