Velix @ 2020-04-19 23:38:28
#include<bits/stdc++.h>
using namespace std;
struct qq{int dis,to,next;}a[500001];
int head[50001],vis[50001],que[10000001],s[50001],tot,h,t,n,m,ans,b,l,r,mi;
long long dis[50001];
void add(int x,int y,int z){a[++tot].to=y;a[tot].dis=z;a[tot].next=head[x];head[x]=tot;}
bool check(int num)
{
if(s[1]>num)return 0;
for(int i=1;i<=n;i++)dis[i]=1000000001;
dis[1]=0;vis[1]=1;que[1]=1;
h=0;t=1;
while(h<=t)
{
h++;
for(int i=head[que[h]];i;i=a[i].next)
if(a[i].dis+dis[que[h]]<dis[a[i].to])
{
dis[a[i].to]=a[i].dis+dis[que[h]];
if(!vis[a[i].to]&&s[a[i].to]<=num)
{
que[++t]=a[i].to;
vis[a[i].to]=1;
}
}
vis[que[h]]=0;
}
return dis[n]<b;
}
int main()
{
int u,v,w;
cin>>n>>m>>b;
for(int i=1;i<=n;i++){scanf("%d",&s[i]);r=max(r,s[i]);}
l=max(s[1],s[n]);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
if(u==v)continue;
add(u,v,w);
add(v,u,w);
}
if(!check(1000000000)){cout<<"AFK";return 0;}
while(l<=r)
{
mi=(l+r)/2;
if(check(mi))r=mi-1,ans=mi;
else l=mi+1;
}
cout<<ans;
}
用的SPFA勿喷
by IceYukino @ 2020-04-20 06:49:02
SPFA告诉我前路在何方……