tyvj P1248 - 丛林探险
P1248 - 丛林探险From Admin Normal (OI) 总时限:10s 内存限制:128MB |
||||||
---|---|---|---|---|---|---|
|
Delphi语言: 高亮代码由发芽网提供
program tyvj1248;
type node=record
a,b:longint;
end;
var b:array[0..80000,1..4] of longint;
a:array[0..5000] of longint;
q:array[1..10000] of integer;
d:array[1..5000] of node;
mark:array[1..5000] of boolean;
n,m,x,y,l,sum,k,t,head,tail,first,c,z,kk,i,s:longint;
procedure push(k:longint);
begin
inc(head);q[head]:=k;
mark[k]:=true;
end;
function pop:longint;
begin
pop:=q[tail];
inc(tail);
end;
begin
readln(n,m);z:=0;
for i:=1 to m do begin
readln(x,y,c,s);
inc(z);b[z,1]:=y;b[z,2]:=c;b[z,3]:=s;b[z,4]:=a[x];a[x]:=z;
inc(z);b[z,1]:=x;b[z,2]:=c;b[z,3]:=s;b[z,4]:=a[y];a[y]:=z;
end;
readln(first,l);
readln(sum);
for i:=1 to n do begin
d[i].a:=maxlongint;d[i].b:=maxlongint;
end;
d[first].a:=0;d[first].b:=0;
head:=0;tail:=1;
push(first);
while head>=tail do begin
k:=pop;kk:=a[k];
while kk<>0 do begin
t:=b[kk,1];c:=b[kk,2];s:=b[kk,3];
if (d[k].a+c<=sum)and((d[k].b+s<d[t].b)or((d[k].b+s=d[t].b)and(d[k].a+c<d[t].a))) then begin
d[t].a:=d[k].a+c;
d[t].b:=d[k].b+s;
if not mark[t] then push(t);
end;
kk:=b[kk,4];
end;
mark[k]:=false;
end;
if d[l].a<=sum then writeln(d[l].b)
else writeln(-1);
end.