zby2_ @ 2024-07-01 17:04:28
#include<bits/stdc++.h>
using namespace std;
struct node{
int id,x;
};
vector<node>a[50005];
queue<int>q;
int n,m,b,f[50005],u,v,dis;
int w[50005],is[50005]={};
bool spfa(int maxs){
if(f[1]>maxs) return 0;
memset(w,0x3f,sizeof(w));
memset(is,0,sizeof(is));
w[1]=0;
q.push(1);
while(!q.empty()){
u=q.front();q.pop();
is[u]=0;
for(int i=0;i<a[u].size();++i){
v=a[v][i].id,dis=w[u]+a[u][i].x;
if(dis>b) continue;
if(f[v]>maxs || dis>=w[v]) continue;
if(v==n) return 1;
w[v]=dis;
if(!is[v]) q.push(v),is[v]=1;
}
}
return 0;
}
int main(){
cin>>n>>m>>b;
for(int i=1;i<=n;++i) cin>>f[i];
for(int i=1;i<=m;++i){
cin>>u>>v>>dis;
a[u].push_back({v,dis});
a[v].push_back({u,dis});
}
int l=0,r=1e9+10,mid;
while(l<r){
mid=(l+r)>>1;
if(spfa(mid)) r=mid;
else l=mid+1;
}
if(r==1e9+10) cout<<"AFK\n";
else cout<<r<<endl;
return 0;
}
提交记录:https://www.luogu.com.cn/record/163599768