carter666 @ 2023-09-04 21:36:01
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, m, b, idx, ans = 0x3f3f3f3f;
int e[N], ne[N], mm[N], h[N], f[N], d[N], st[N];
void add(int a, int b, int c){
e[++idx] = b;
ne[idx] = h[a];
h[a] = idx;
mm[idx] = c;
}
bool SPFA(int mid){
memset(st, 0, sizeof(st));
memset(d, 0x3f, sizeof(d));
queue<int> q;
d[1] = 0;
st[1] = 1;
q.push(1);
while(!q.empty()){
int t = q.front();
q.pop();
for (int i = h[t]; i; i = ne[i]){
int y = e[i];
if(d[y] > d[t] + mm[t] && f[y] <= mid){
d[y] = d[t] + mm[t];
if(!st[y]){
q.push(y);
st[y] = 1;
}
}
}
st[t] = 0;
}
return d[n] <= b;
}
signed main(){
cin.tie(0);
cin >> n >> m >> b;
int l = 0x3f3f3f3f, r = 1;
for (int i = 1; i <= n; i++){
cin >> f[i];
l = min(l, f[i]);
r = max(r, f[i]);
}
for (int i = 1; i <= m; i++){
int a, b, c;
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
}
if(!SPFA(0x3f3f3f3f)) {
cout << "AFK" << endl;
return 0;
}
while(l < r){
int mid = (l + r) >> 1;
if (SPFA(mid))
r = mid;
else
l = mid + 1;
// cout << l << " " << r << endl;
}
cout << l << endl;
return 0;
}