#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define SI(a) scanf("%d",&a)
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e6+10;
using namespace std;
int ans;
int a[maxn];
struct Edge{
int from,to,dis;
};
struct HeapNode{
int d,u;
bool operator < (const HeapNode& rhs) const{
return d > rhs.d;
}
};
int n,m,b;
int cnt;
vector<Edge>edges;
vector<int>G[maxn];
bool done[maxn];
int dis[maxn];
int p[maxn];
void init(int n){
for(int i = 0;i <= n;i++)G[i].clear();
cnt = 0;
edges.clear();
}
void AddEdge(int from,int to,int dis){
edges.push_back((Edge){from,to,dis});
cnt = edges.size();
G[from].push_back(cnt-1);
}
bool Dijkstra(int val){
priority_queue<HeapNode>Q;
for(int i = 0;i <= n;i++)dis[i] = INF;
dis[1] = 0;
ms(done,false);
Q.push((HeapNode){0,1});
while(!Q.empty())
{
HeapNode x = Q.top();Q.pop();
int u = x.u;
if(done[u])continue;
done[u] = true;
for(int i = 0;i <(int)G[u].size();i++)
{
Edge& e = edges[G[u][i]];
if(dis[e.to] > dis[u] + e.dis && a[e.to] <= val){
dis[e.to] = dis[u]+ e.dis;
Q.push((HeapNode){dis[e.to],e.to});
}
}
}
return dis[n] <= b;
}
int main()
{
int l,r = -1;
cin>>n>>m>>b;
init(n);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
if(r < a[i])
r = a[i];
}
l = min(a[1],a[n]);
for(int i = 0;i < m;i++)
{
int u,v,dis;
cin>>u>>v>>dis;
AddEdge(u,v,dis);
AddEdge(v,u,dis);
}
if(!Dijkstra(r))cout<<"AFK"<<endl;
else{
while(l != r)
{
int mid = l + (r-l)/2;
if(!Dijkstra(mid))l = mid+1;
else r = mid ;
}
cout<<l<<endl;
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-33635.html