破壁人 @ 2017-12-19 14:05:38
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int _=10001;
const int INF=1500000000;
long long x[_],n,m,hp,l,r,mid;
long long s1[_];
vector<long long> a[_],b[_];
bool bo,xc[10001];
queue<long long>q;
void spfa1()
{
while(q.size()!=0)
{
long long yu=q.front();
for(int i=0;i<a[yu].size();i++)
if((x[a[yu][i]]<=mid)&&(s1[yu]+b[yu][i]<s1[a[yu][i]]))
{
s1[a[yu][i]]=s1[yu]+b[yu][i];
if(!xc[a[yu][i]])
{
xc[a[yu][i]]=true;
q.push(a[yu][i]);
}
}
xc[yu]=false;
q.pop();
}
}
int main()
{
scanf("%lld%lld%lld",&n,&m,&hp);r=0;
for(int i=1;i<=n;i++) scanf("%lld",&x[i]),r=max(r,x[i]);
r++;r++;
l=max(x[1],x[n]);
for(int i=1;i<=n;i++)
{
long long x,y,z;
scanf("%lld%lld%lld",&x,&y,&z);
a[x].push_back(y);b[x].push_back(z);
a[y].push_back(x);b[y].push_back(z);
}
bool bo1=false;
while(l<r)
{
mid=(l+r)/2;
memset(xc,0,sizeof(xc));
for(int i=1;i<=n;i++) s1[i]=INF;
xc[1]=true;
s1[1]=0;
q.push(1);
if(x[1]<=mid) spfa1();
if(s1[n]<hp)bo=true;else bo=false;
if(bo){bo1=true;r=mid;}else l=mid+1;
}
if(bo1)printf("%lld\n",l);else printf("AFK\n");
return 0;
}