wangyansong @ 2020-10-31 16:43:33
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#define inf 0x3f3f3f3f
struct edge{
int v,w,next;
}e[100010];
int ans,head[10010],dis[10010],n,m,vis[10010],cnt,b,c[10010],a[10010];
int add(int u,int v,int w){
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].next=head[u];
head[u]=cnt;
}
bool spfa(int top)
{
memset(dis,0x3f,sizeof(dis));
memset(vis,0,sizeof(vis));
queue<int> q;
vis[1]=true;dis[1]=0;
q.push(1);
while(!q.empty())
{
int temp=q.front();q.pop();
vis[temp]=false;
for(int i=head[temp];i!=0;i=e[i].next)
{
int to=e[i].v;
int wr=e[i].w;
if(dis[to]>dis[temp]+wr&&c[to]<=top)
{
dis[to]=dis[temp]+wr;
if(vis[to]==false)
{
vis[to]=true;
q.push(to);
}
}
}
}
if(dis[n]<=b)
{
return true;
}else{
return false;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&b);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);c[i]=a[i];
}
for(int i=1;i<=m;++i){
static int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
sort(c+1,c+n+1);
int l=1,r=n,mid;
if(!spfa(inf)){
printf("AFK\n");
return 0;
}
ans=0;
while(l<=r){
mid=(l+r)/2;
if(spfa(c[mid])) ans=c[mid],r=mid-1;
else l=mid+1;
}
printf("%d\n",ans);
}
by wangyansong @ 2020-10-31 17:21:03
提交43次,错在```c if(dis[to]>dis[temp]+wr&&c[to]<=top)
是a【to】不是c【to】