7000qwq @ 2018-10-11 12:27:17
调了一上午啦qwq!3AC 8WA 哭哭
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<deque>
#define ll long long
using namespace std;
deque<int> p;
ll dis[10001];
int vis[10001];
int n,m;
ll b;
int qaq[10001];
int ww[10001];
struct edge
{int to;
int next;
ll bl;
}s[100001];
int num=0;
int h[10001];
void addedge(int x,int y,ll ww)
{num++;
s[num].to=y;
s[num].bl=ww;
s[num].next=h[x];
h[x]=num;
}
bool spfa(int wx)//最大花费不超过w[x]
{
for(int i=1;i<=n;i++)
dis[i]=1000000100;
memset(vis,0,sizeof(vis));
p.push_front(1);
dis[1]=0;
vis[1]=1;
while(!p.empty())
{int g=p.front();
p.pop_front();
vis[g]=0;
for(int i=h[g];i!=0;i=s[i].next)
{int v=s[i].to;
if(dis[v]>dis[g]+s[i].bl&&wx>=ww[v])
{dis[v]=dis[g]+s[i].bl;
if(!vis[v])
{vis[v]=1;
p.push_back(v);
}
}
}
}
if(dis[n]<=b)
return 1;
return 0;
}
int findans(int l,int r)
{if(l==r) return l;
int mid=(l+r)/2;
if( spfa(ww[mid]) ) return findans(l,mid);
else return findans(mid+1,r);
}
int main()
{scanf("%d%d%lld",&n,&m,&b);
int maxn=-1;
for(int i=1;i<=n;i++)
{scanf("%d",&qaq[i]);
ww[i]=qaq[i];
maxn=max(maxn,ww[i]);
}
sort(qaq+1,qaq+1+n);
int x,y;
ll bl;
for(int i=1;i<=m;i++)
{scanf("%d%d%lld",&x,&y,&bl);
if(x!=y)
{addedge(x,y,bl);
addedge(y,x,bl);
}
}
if(spfa(maxn)==0)
{cout<<"AFK";
return 0;
}
cout<<ww[findans(1,n)];
}