比赛 |
20101116 |
评测结果 |
WTTTTWWAWW |
题目名称 |
城市 |
最终得分 |
10 |
用户昵称 |
ZhouZn1 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-16 11:02:29 |
显示代码纯文本
program zzn;
var
n,i,j,m,u,v,s,x,y,z,ans,max,k:longint;
a,aa:array[1..200,1..200]of longint;
vv:array[1..200,1..200]of boolean;
b:array[1..200,0..200]of longint;
cost:array[1..10000]of longint;
procedure closef;
begin
close(input);
close(output);
end;
procedure init;
begin
assign(input,'cost.in');
reset(input);
assign(output,'cost.out');
rewrite(output);
readln(n,m,u,v,s);
if n>200 then
begin
writeln(-1);
halt;
end;
fillchar(a,sizeof(a),255);
fillchar(b,sizeof(b),0);
for i:=1 to n do readln(cost[i]);
for i:=1 to m do
begin
readln(x,y,z);
a[x,y]:=z;
a[y,x]:=z;
inc(b[x,0]);
inc(b[y,0]);
b[x,b[x,0]]:=y;
b[y,b[y,0]]:=x;
end;
fillchar(vv,sizeof(vv),0);
aa:=a;
for k:=1 to n do
for i:=1 to n do if i<>k then
for j:=1 to n do if j<>i then
if (aa[k,j]<>-1)and(aa[i,k]<>-1)then
if (aa[i,j]=-1)or(aa[i,j]>aa[i,k]+aa[k,j]) then
aa[i,j]:=aa[i,k]+aa[k,j];
if aa[u,v]>s then
begin
writeln(-1);
closef;
halt;
end;
end;
procedure dfs(x:integer;cc,lu,ss:longint);
var
i:integer;
begin
if x=v then
begin
if lu>max then
begin
max:=cc;
ans:=ss;
end else
if lu=max then
if ss<ans then ans:=ss;
exit;
end;
for i:=1 to b[x,0] do
if cc+a[x,b[x,i]]<=s then
begin
if a[x,b[x,i]]>ss then ss:=a[x,b[x,i]];
dfs(b[x,i],cc+a[x,b[x,i]],lu+cost[x],ss);
end;
end;
procedure main;
begin
ans:=maxlongint;
max:=-maxlongint;
dfs(u,0,0,-maxlongint);
writeln(ans);
end;
begin
init;
main;
closef;
end.