比赛 20101116 评测结果 MMMMMMMMMM
题目名称 城市 最终得分 0
用户昵称 make 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-16 11:22:59
显示代码纯文本
program cost;
var
  n,m,u,v,s,ans:longint;
  h,num:array [1..10000,1..10000] of longint;
  o:array [1..10000] of boolean;
  a:array [1..10000] of longint;
  f1,f2:text;

procedure init;
var i,j,x,y,k:longint;
begin
 assign(f1,'cost.in'); reset(f1);
 assign(f2,'cost.out'); rewrite(f2);
 readln(f1,n,m,u,v,s);
 for i:=1 to n do
  for j:=1 to n do begin
   h[i,j]:=maxlongint;
   num[i,j]:=0;
  end;
 for i:=1 to n do
  readln(f1,a[i]);
 for i:=1 to m do begin
  readln(f1,x,y,k);
  h[x,y]:=k;
 end;
 close(f1);
 for i:=1 to n do
  if h[u,i]<>maxlongint then
   if a[u]>a[i] then num[u,i]:=a[u]
   else num[u,i]:=a[i];
end;

procedure fl;
var i,j,k,min,sp:longint;
begin
 sp:=0;
 for k:=1 to n do
  for i:=1 to n do
   for j:=1 to n do
    if (h[i,k]<>maxlongint)and(h[k,j]<>maxlongint) then begin
     if h[i,k]+h[k,j]<h[i,j] then h[i,j]:=h[i,k]+h[k,j];
     if a[k]>num[i,j] then num[i,j]:=a[k];
     if a[j]>num[i,j] then num[i,j]:=a[j];
     if a[i]>num[i,j] then num[i,j]:=a[i];
     if (i=u)and(j=v)and(sp=0) then begin inc(sp); ans:=num[i,j]; end;
     if (i=u)and(j=v)and(sp>0) then begin if num[i,j]<ans then ans:=num[i,j] end
    end;
end;

procedure print;
begin
 if (h[u,v]>s) then write(f2,-1)
 else write(f2,ans);
 close(f2);
end;

begin
 init;
 fl;
 print;
end.