- 丛林探险
- 2014-11-03 20:56:58 @
#include<stdio.h>
#include<queue>
#include<iostream>
using namespace std;
struct xx
{
long long dian,tl=1000000005,cd=1000000005;
};
xx line[80005],minp[5005];
int next[40005],head[5005],x,y,c,d,st,en,tottl,m,n;
long long ans=-1;
queue<int> q;
void read()
{
int zhizhen=0;
for(int i=1;i<=m;i++)
{
cin>>x>>y>>c>>d;
line[++zhizhen].dian=x;
line[zhizhen].cd=d;
line[zhizhen].tl=c;
next[zhizhen]=head[y];
head[y]=zhizhen;
line[++zhizhen].dian=y;
line[zhizhen].cd=d;
line[zhizhen].tl=c;
next[zhizhen]=head[x];
head[x]=zhizhen;
}
}
void dfs(int i,long long tlnow,long long lc)
{
minp[i].tl=min(minp[i].tl,tlnow);
minp[i].cd=min(minp[i].cd,lc);
if(i==en)
{
if(ans==-1)
ans=lc;
ans=min(ans,lc);
return ;}
int k=head[i];
while(k!=0)
{
if(line[k].tl+tlnow<=tottl&&(minp[line[k].dian].tl>line[k].tl+tlnow||minp[line[k].dian].cd>line[k].cd+lc))
dfs(line[k].dian,tlnow+line[k].tl,lc+line[k].cd);
k=next[k];
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
read();
cin>>st>>en>>tottl;
dfs(st,0,0);
cout<<ans;
}