#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 10010, M = 100010;
int n,m,k;
struct P
{
int cst; //管城市点数的
int dis,cnt; //管边权值总和的
bool st;
}ptn[N];
struct Edge
{
int b,v,nxt;
}edge[M];
int head[N],tot;
void add(int a,int b,int c)
{
edge[++tot].b = b;
edge[tot].v = c;
edge[tot].nxt = head[a];
head[a] = tot;
}
typedef pair<int, int> PII;
priority_queue<PII,vector<PII>,less<PII> > q;
bool flag = true;
bool diji()
{
ptn[1].cnt = 1;
// 经过城市点数最多的,花钱最少的一次是多少
q.push(make_pair(ptn[1].cnt,1));
while(q.size())
{
int cnt = q.top().first , u = q.top().second;
q.pop();
ptn[u].st = 1;
if(ptn[u].dis > k && u != n)
{
continue;
flag = false;
}
for(int i = head[u]; i ; i = edge[i].nxt)
{
int j = edge[i].b , v = edge[i].v;
int cst = ptn[j].cst;
if(ptn[j].cnt < cnt + 1)
{
ptn[j].cnt = cnt + 1;
ptn[j].dis = ptn[u].dis + v;
ptn[j].cst = ptn[u].cst + cst;
if(!ptn[j].st)
{
ptn[j].st = 1;
q.push({ptn[j].cnt,j});
}
}
else if(ptn[j].cnt == cnt + 1)
{
ptn[j].cst = min(ptn[j].cst , ptn[u].cst + cst);
ptn[j].dis = min(ptn[j].dis , ptn[u].dis + v);
}
}
}
return flag;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i = 1; i <= n; i++) scanf("%d",&ptn[i].cst);
int a,b,c;
while (m --)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
if(diji()) cout<<ptn[n].cst<<endl;
else puts("AFK");
return 0;
}