whb569 @ 2022-11-22 14:25:01
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
#include <cstring>
using namespace std;
int n,m,b,f[10005],vis[10005];
long long dis[10005];
struct node{
int to;
long long dis;
bool operator <(const node &rhs)const{
return rhs.dis<dis;
}
};
vector<int> g[10005];
vector<node> edges;
priority_queue<node> q;
int dijkistra(int h)
{
for(int i =1;i<=n;i++)dis[i]=LLONG_MAX/3;
memset(vis,0,sizeof(vis));
q.push((node){1,0});
dis[1]=0;
while(!q.empty())
{
node x=q.top();
q.pop();
int u=x.to;
if(vis[u])continue;
vis[u]=1;
for(int i =0;i<g[u].size();i++)
{
node v=edges[g[u][i]];
if(f[v.to]>h)continue;
if(dis[v.to]>dis[u]+v.dis){
dis[v.to]=dis[u]+v.dis;
q.push((node){v.to,dis[v.to]});
}
}
}
return dis[n]<=b;
}
int main()
{
int x,y;
long long z;
int r=0;
int ic=0;
cin>>n>>m>>b;
for(int i =1;i<=n;i++)
{
cin>>f[i];
r=max(f[i],r);
}
for(int i =1;i<=m;i++)
{
cin>>x>>y>>z;
edges.push_back((node){y,z});
edges.push_back((node){x,z});
g[x].push_back(ic++);
g[x].push_back(ic++);
}
if(!dijkistra(1000000005))
{
cout<<"AFK";
return 0;
}
int l=max(f[1],f[n]);
while(l<=r)
{
int mid=(l+r)>>1;
if(dijkistra(mid))r=mid-1;
else l=mid+1;
}
cout<<l;
}