Trouble_KING @ 2023-11-15 15:39:57
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
const int M = 1e5 + 10;
const int inf = 1e9 + 7;
int f[N], dis[N], pre[N];
struct G {
int cnt = 0;
struct edge {
int v, w, ne;
} e[M];
inline void add(int u , int v, int w) {
e[++cnt] = (edge){v, w, pre[u]};
pre[u] = cnt;
return;
}
struct node {
int u, dis;
bool operator > (const node &x) const {
if(u == x.u) return dis > x.dis;
else return u > x.u;
}
};
priority_queue<node, vector<node>, greater<node> > Q;
} g;
bool vis[N];
int n, m, b;
inline bool check(int x) {
if(x < f[1]) return false;
for(int i = 1;i <= n;i++) dis[i] = 0x3f3f3f3f, vis[i] = false;
dis[1] = 0;
g.Q.push({1, 0});
while (!g.Q.empty()) {
int u = g.Q.top().u;
g.Q.pop();
if(vis[u]) continue;
vis[u] = true;
for(int i = pre[u];i;i = g.e[i].ne) {
int v = g.e[i].v, w = g.e[i].w;
if(dis[v] > dis[u] + w && f[v] <= x && !vis[v]) {
dis[v] = dis[u] + w;
g.Q.push({v, dis[v]});
}
}
}
if(dis[n] < b) return true;
else return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> b;
for(int i = 1;i <= n;i++) cin >> f[i];
for(int i = 1;i <= m;i++) {
int u, v, w;
cin >> u >> v >> w;
g.add(u, v, w);
g.add(v, u, w);
}
if(!check(inf)) {
cout << "AFK" << endl;
return 0;
}
int l = 1, r = inf;
while(l <= r) {
int mid = l + r >> 1;
if(check(mid)) r = mid - 1;
else l = mid;
}
cout << l << endl;
return 0;
}
玄关