我没有判断起点的金钱值是否满足居然AC了
program df;
type point=^node;
node=record
ends:longint;
date:int64;
next:point;
end;
var i,j,n,m,x,y,z,k,t,l,r:longint;
path:array[0..1000000] of point;
tm:array[0..1000000] of longint;
a,b,dis:array[0..100000] of int64;
d:array[0..100000] of boolean;
procedure sq(l,r:longint);
var i,j,mm,dd:longint;
begin
i:=l; j:=r;
mm:=b[(l+r) div 2];
repeat
while b[i]<mm do inc(i);
while b[j]>mm do dec(j);
if i<=j then
begin
dd:=b[i]; b[i]:=b[j]; b[j]:=dd;
inc(i); dec(j);
end;
until i>j;
if l<j then sq(l,j);
if i<r then sq(i,r);
end;
procedure com(x,y,z:longint);
var i:point;
begin
i:=path[x];
new(path[x]);
path[x]^.ends:=y;
path[x]^.date:=z;
path[x]^.next:=i;
end;
procedure init;
var i,j:longint;
begin
for i:=1 to n do
begin
dis[i]:=10000000000;
d[i]:=false;
end;
end;
procedure spfa(x:longint);
var i:point;
h,t,u,y:longint;
begin
init;
h:=0; t:=1; tm[1]:=1; dis[1]:=0;
repeat
inc(h);
u:=tm[h];
d[u]:=false;
i:=path[u];
while i<>nil do
begin
y:=i^.ends;
if (a[y]<=x) and (dis[y]>dis[u]+i^.date) then
begin
dis[y]:=dis[u]+i^.date;
if not d[y] then
begin
d[y]:=true;
inc(t);
tm[t]:=y;
end;
end;
i:=i^.next;
end;
until h=t;
end;
begin
readln(n,m,k);
for i:=1 to n do
readln(a[i]);
b:=a;
sq(1,n);
for i:=1 to m do
begin
readln(x,y,z);
com(x,y,z);
com(y,x,z);
end;
l:=1; r:=n;
while l<r do
begin
m:=(l+r) div 2;
spfa(b[m]);
if dis[n]<=k then r:=m
else l:=m+1;
end;
if l>r then begin x:=l; l:=r; r:=x; end;
spfa(b[l]);
if dis[n]<=k then begin writeln(b[l]); halt; end;
spfa(b[r]);
if dis[n]<=k then begin writeln(b[r]); halt; end;
writeln('AFK');
end.