1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<cstring> using namespace std; long long read() { long long x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } const int N=10000+100; const int V_MAX=1000000000; struct road { int to,dis; friend bool operator < (road A,road B) { return A.dis > B.dis; } }; vector <road> e[N]; priority_queue <road,vector<road> > dl; int dis[N],vis[N],n,m,b,v[N]; void dj(int lim) { while(dl.empty()==false) dl.pop(); memset(dis,0x3f,sizeof dis); memset(vis,0,sizeof vis); if(v[1]>lim) return; road now; now.to=1,now.dis=0,dis[1]=0; dl.push(now); while(dl.empty()==false) { now=dl.top(); dl.pop(); if(vis[now.to]==true) continue; vis[now.to]=true; for(int i=0;i<int(e[now.to].size());i++) if(dis[e[now.to][i].to] > now.dis+e[now.to][i].dis and v[e[now.to][i].to]<=lim) { dis[e[now.to][i].to]=now.dis+e[now.to][i].dis; road temp; temp.to=e[now.to][i].to,temp.dis=dis[e[now.to][i].to]; dl.push(temp); } } } int main() { n=read(),m=read(),b=read(); for(int i=1;i<=n;i++) { e[i].reserve(4); v[i]=read(); } for(int i=1;i<=m;i++) { int a=read(),b=read(),c=read(); road temp; temp.dis=c,temp.to=b; e[a].push_back(temp); temp.to=a; e[b].push_back(temp); }
int L=0,R=V_MAX,ans=0x3f3f3f3f; while(L<=R) { int mid=(L+R)/2; dj(mid); if(dis[n]<=b) { ans=min(ans,mid); R=mid-1; } else L=mid+1; }
if(ans!=0x3f3f3f3f) printf("%d",ans); else printf("AFK"); return 0; }
|