比赛 |
20101116 |
评测结果 |
WWWWWEEEEA |
题目名称 |
城市 |
最终得分 |
10 |
用户昵称 |
belong.zmx |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-16 11:07:06 |
显示代码纯文本
program cost(input,output);
var
n,m:longint;
u,v,s:longint;
w:array[1..200]of longint;
a:array[1..200,1..200]of longint;
i,j:longint;
f:array[1..200,0..200]of longint;
x,y,z:longint;
t:array[1..200,0..200]of boolean;
q:array[1..10000,1..2]of longint;
head,tail,ans:longint;
function max(a,b:longint):longint;
begin
if a>b then max:=a else max:=b;
end;
begin
assign(input,'cost.in');
reset(input);
readln(n,m,u,v,s);
for i:=1 to n do
for j:=1 to s do
f[i,j]:=maxlongint;
for i:=1 to n do
for j:=1 to n do
begin
a[i,j]:=-1;
end;
for i:=1 to n do readln(w[i]);
for i:=1 to m do
begin
readln(x,y,z);
a[x,y]:=z;
end;
close(input);
head:=1;
tail:=1;
q[head,1]:=u;
q[head,2]:=0;
f[u,0]:=w[u];
t[u,0]:=true;
repeat
for i:=1 to n do
if (a[q[head,1],i]>-1)and(f[i,q[head,2]+a[q[head,1],i]]>max(f[q[head,1],q[head,2]],w[i])) then
begin
if t[i,q[head,2]+a[q[head,1],i]]=true then
begin
f[i,q[head,2]+a[q[head,1],i]]:=max(f[q[head,1],q[head,2]],w[i]);
end
else
begin
inc(tail);
q[tail,1]:=i;
q[tail,2]:=q[head,2]+a[q[head,1],i];
f[i,q[head,2]+a[q[head,1],i]]:=max(f[q[head,1],q[head,2]],w[i]);
t[i,q[head,2]+a[q[head,1],i]]:=true;
end;
end;
t[q[head,1],q[head,2]]:=false;
inc(head);
until head>tail;
ans:=maxlongint;
for i:=s downto 1 do
if f[v,i]<ans then ans:=f[v,i];
assign(output,'cost.out');
rewrite(output);
if (ans=maxlongint)or(v>n) then writeln('-1')
else writeln(ans);
close(output);
end.