#include <iostream> #include <cstdio> #include <queue> #include <algorithm> #include <cstring> using namespace std; const int maxn=10010; const int maxm=50010; const int INF=1<<30; struct edge{int v,b;}; int n,m,b,cost[maxn],d[maxn],s=1,t,ans; bool vis[maxn]; vector<edge> G[maxm]; queue<int> q; bool spfa(int x){ memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++)d[i]=INF; q.push(s); d[s]=0; vis[s]=1; if(cost[s]>x)return false; while(!q.empty()){ int u=q.front(); q.pop(); vis[u]=0; for(int i=0;i<G[u].size();i++){ int v=G[u][i].v,rd=G[u][i].b; if(d[u]+rd<d[v] && d[u]+rd<=b && cost[v]<=x){ d[v]=d[u]+rd; if(!vis[v]){q.push(v); vis[v]=1;} } } } return d[t]!=INF; } int main(){ scanf("%d%d%d",&n,&m,&b); t=n; int l=0,r=0; for(int i=1;i<=n;i++){scanf("%d",&cost[i]); r=max(r,cost[i]);} while(m--){ int u,v,b; scanf("%d%d%d",&u,&v,&b); G[u].push_back((edge){v,b}); G[v].push_back((edge){u,b}); } while(l<=r){ int mid=(l+r)/2; if(spfa(mid)){ ans=mid; r=mid-1; } else l=mid+1; } if(!ans)puts("AFK"); else printf("%d ",ans); return 0; }