_x_y_ @ 2022-07-28 22:30:25
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
vector<int> v[N], e[N];
int n, m, b, a[N];
long long dis[N];
bool vis[N];
void spfa(long long mid){
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; i++)
dis[i] = 1e18;
if(a[1] > mid)
return;
queue<int> q;
q.push(1);
vis[1] = 1;
dis[1] = 0;
while(!q.empty()){
int x = q.front();
q.pop();
vis[x] = 0;
if(a[x] > mid)
continue;
for(int i = 0; i < v[x].size(); i++){
int y = v[x][i], z = e[x][i];
if(a[y] > mid)
continue;
if(dis[y] > dis[x] + z){
dis[y] = dis[x] + z;
if(!vis[i]){
q.push(y);
vis[y] = 1;
}
}
}
}
}
int main(){
cin >> n >> m >> b;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= m; i++){
int u, vv, w;
cin >> u >> vv >> w;
v[vv].push_back(u);
e[vv].push_back(w);
v[u].push_back(vv);
e[u].push_back(w);
}
int l = 0, r = 1e9;
while(l < r){
int mid = (l + r) >> 1;
spfa(mid);
if(dis[n] > b)
l = mid + 1;
else
r = mid;
}
spfa(r);
if(dis[n] > b)
puts("AFK");
else
printf("%d\n", r);
return 0;
}
by YGB_XU @ 2022-07-28 23:45:29
if(!vis[i])
应改为 if(!vis[y])
by _x_y_ @ 2022-07-29 07:17:32
谢谢dalao