比赛 20111110 评测结果 WWWWWWWWWA
题目名称 城市 最终得分 10
用户昵称 lizhe 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-11-10 11:28:32
显示代码纯文本
program cost;
const
  maxtin=10000000;
var
  i,j,n,m,u,v,s,l,r,mid,x,y,z,min1,min2,max,head,tail:longint;
  a,num,d,t:array[1..10000]of longint;
  flag:array[1..10000]of boolean;
  map,w:array[1..10000,1..500]of longint;
  que:array[1..1000000]of longint;
procedure swap(var a0,b0:longint);
var
  c0:longint;
begin
  c0:=a0;
  a0:=b0;
  b0:=c0
end;

procedure sort(l,r:longint);
var
  i,j,x:longint;
begin
  i:=l;
  j:=r;
  x:=a[(l+r) div 2];
  repeat
    while a[i]<x do inc(i);
    while x<a[j] do dec(j);
    if i<=j then
    begin
      swap(a[i],a[j]);
      swap(num[i],num[j]);
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then sort(l,j);
  if i<r then sort(i,r);
end;

procedure init;
begin
  assign(input,'cost.in');
  reset(input);
  assign(output,'cost.out');
  rewrite(output);
  read(n,m,u,v,s);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do num[i]:=i;
  for i:=1 to m do
  begin
    read(x,y,z);
    inc(t[x]);
    map[x,t[x]]:=y;
    w[x,t[x]]:=z;
    inc(t[y]);
    map[y,t[y]]:=x;
    w[y,t[y]]:=z;
  end;
  sort(1,n)
end;

procedure spfa(x,y:longint);
begin
  fillchar(flag,sizeof(flag),true);
  for i:=1 to n do d[i]:=maxtin;
  d[x]:=0;
  flag[x]:=false;
  que[1]:=x;
  head:=0;
  tail:=1;
  while  head<tail do
  begin
    inc(head);
    for i:=1 to t[que[head]] do
      if (d[map[que[head],i]]>d[que[head]]+w[que[head],i]) and (a[map[que[head],i]]<=max) then
      begin
        d[map[que[head],i]]:=d[que[head]]+w[que[head],i];
        if flag[map[que[head],i]] then
        begin
          flag[map[que[head],i]]:=false;
          inc(tail);
          que[tail]:=map[que[head],i]
        end
      end;
    flag[que[head]]:=true
  end
end;

function ok:boolean;
begin
  ok:=true;
  max:=a[l];
  spfa(u,num[l]);
  min1:=d[num[l]];
  spfa(num[l],v);
  min2:=d[v];
  if min1+min2>s then ok:=false
end;

procedure erfen;
begin
   l:=1; r:=n;
   while l<r do
   begin
     mid:=(l+r) shr 1;
     if ok then r:=mid
     else l:=mid+1
   end;
   mid:=l;
   if ok then writeln(a[l])
   else writeln('-1');
   close(input);
   close(output)
end;

begin
  init;
  erfen
end.