Sai0511 @ 2018-11-08 11:44:31
#include<bits/stdc++.h>
#define il inline
#define gc getchar
#define int long long
const int MAXN=1e4+10;
const int MAXM=5e5+10;
const int INF=1000000001;
using namespace std;
int n,m,i,j,k,HP,L,R,cnt,Ans;
int head[MAXN],dis[MAXN],f[MAXN];bool vis[MAXN];
struct Edge{
int to,val,Next;
}G[MAXM];
struct io{
il int read(){
int x=0;char c;
for(c=gc();!isdigit(c);c=gc()) ;
for(;isdigit(c);c=gc()) x=(x<<1)+(x<<3)+(c^48);
return x;
}
}Fio;
#define read Fio.read
il void spfa(){
int i;
queue<int>q;while(!q.empty()) q.pop();q.push(1);
while(!q.empty()){
int u=q.front(); q.pop();vis[u]=0;
for(i=head[u];~i;i=G[i].Next){
int to=G[i].to; int val=G[i].val;
if(dis[u]+val<dis[to]){
dis[to]=dis[u]+val;
if(!vis[to]){
vis[to]=1;
q.push(to);
}
}
}
}
return;
}
il bool Check(int HP){
int i;
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++) dis[i]=INF; dis[1]=0; vis[1]=1;
spfa();
return dis[n]<HP;
}
il void addEdge(int u,int v,int val){
G[++cnt].to=v;G[cnt].val=val;G[cnt].Next=head[u];
head[u]=cnt;return;
}
signed main(){
n=read();m=read();HP=read();
for(i=1;i<=n;i++) f[i]=read(),R=max(R,f[i]);L=max(f[1],f[n]);
memset(head,-1,sizeof(head));
for(i=1;i<=m;i++){
int u=read(),v=read(),d=read();
addEdge(u,v,d);addEdge(v,u,d);
}
if(!Check(INF)){printf("AFK");return 0;}
while(L<=R){
int mid=L+R>>1;
if(Check(mid)) Ans=mid,R=mid-1;
else L=mid+1;
}printf("%lld",1LL*Ans);
return 0;
}