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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| #include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<ext/pb_ds/priority_queue.hpp> using namespace std; const int maxn=10005; typedef long long ll; int n,m,b;
inline ll read() { ll s=0,w=1; char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') w=-1; c=getchar(); } while (c>='0' && c<='9') { s=(s<<3)+(s<<1)+(c^48); c=getchar(); } return s*w; }
struct note{ ll cur,c; note(ll a,ll b):cur(a),c(b) {} note() {} };
struct cmp{ bool operator () (note a,note b) { return a.c>b.c; } };
typedef __gnu_pbds::priority_queue<note,cmp,__gnu_pbds::pairing_heap_tag> heap;
struct edge{ ll to;ll w; edge(ll a,ll b):to(a),w(b) {} edge() {} }; vector<edge> e[maxn]; ll v[maxn];
inline void addedge(ll x,ll y,ll w) { e[x].push_back(edge(y,w)); }
bool vis[maxn]; ll bfs(ll val) { memset(vis,0,sizeof(vis)); heap q; q.push(note(1,0)); vis[1]=true; while(!q.empty()) { note cu=q.top(); q.pop(); if(cu.cur==n){ return cu.c; } ll& st=cu.cur; ll& co=cu.c; for(int i=0;i<e[st].size();i++) { ll& to=e[st][i].to; if(!vis[to] && v[to]<=val) { q.push(note(to,co+e[st][i].w)); vis[to]=true; } } } return 0x3f3f3f3f; }
ll lsv[maxn]; int main() { n=read(),m=read(),b=read(); for(int i=1;i<=n;i++) lsv[i-1]=v[i]=read(); for(int i=1,x,y,w;i<=m;i++) { x=read(),y=read(),w=read(); if(x!=y) addedge(x,y,w),addedge(y,x,w); } sort(lsv,lsv+n); int sz=unique(lsv,lsv+n)-lsv; int l=0,r=sz,mid,ans=-1; while(l<=r) { mid=(l+r)>>1; if(bfs(lsv[mid])<=b) ans=mid,r=mid-1; else l=mid+1; } if(ans==-1){ printf("AFK\n"); return 0; } else printf("%lld\n",lsv[ans]); }
|