思路:
二分答案,然后小于答案的边跑一次最短路就行了
c o d e code code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const ll MAXN = 1e4 + 10;
ll n, m, b, tot;
ll f[MAXN], dis[MAXN], head[MAXN];
bool v[MAXN];
struct node {
ll to, next, w;
}e[MAXN * 10];
void add(ll x, ll y, ll z) {
e[++ tot] = (node) { y, head[x], z };
head[x] = tot;
}
bool check(ll maxx) {
for(ll i = 1; i <= n; i ++) dis[i] = 1e18, v[i] = 0;
dis[1] = 0;
priority_queue<pair<int, int> > q;
q.push(make_pair(0, 1));
if(f[1] > maxx) return 0;
while(!q.empty()) {
ll x = q.top().second;
q.pop();
if(v[x]) continue;
v[x] = 1;
for(ll i = head[x]; i; i = e[i].next) {
if(f[e[i].to] <= maxx && dis[e[i].to] > dis[x] + e[i].w) {
dis[e[i].to] = dis[x] + e[i].w;
q.push(make_pair(-dis[e[i].to], e[i].to));
}
}
}
return dis[n] <= b;
}
int main() {
scanf("%lld%lld%lld", &n, &m, &b);
for(ll i = 1; i <= n; i ++) scanf("%lld", &f[i]);
for(ll i = 1; i <= m; i ++) {
ll x, y, z;
scanf("%lld%lld%lld", &x, &y, &z);
add(x, y, z), add(y, x, z);
}
ll l = 1, r = 1e9, ans = 1e9;
while(l <= r) {
ll mid = l + r >> 1;
if(check(mid)) r = mid - 1, ans = min(ans, r);
else l = mid + 1;
}
if(ans == 1e9) printf("AFK");
else printf("%lld", r + 1);
return 0;
}