顾小伍 @ 2019-08-27 09:49:57
第一个点判断能否到达我都判错了
by 顾小伍 @ 2019-08-27 10:07:59
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
register int r=0,f=1;
register char e=getchar();
while(!isdigit(e)){
if(e=='-')
f=-1;
e=getchar();
}
while(isdigit(e))
r=(r<<1)+(r<<3)+e-'0',e=getchar();
return r*f;
}
const int maxd=10001,maxn=50001;
struct code{
int next,to,w;
}edge[maxn*2];
struct node{
int id,dep;
node(int a=0,int b=0):id(a),dep(b){}
bool operator<(node a)const{
return dep>a.dep;
}
};
int cost[maxd],cnt,fir[maxn*2],dis[maxd],n,m,hp;
bool in[maxd];
inline void add(int a,int b,int t){
edge[++cnt].next=fir[a];
edge[cnt].to=b;
edge[cnt].w=t;
fir[a]=cnt;
}
inline bool check(int arr){
if(arr<cost[1] || arr<cost[n])
return 0;
memset(dis,0x7f,sizeof(dis));
memset(in,0,sizeof(in));
dis[1]=0;
in[1]=true;
priority_queue<node>que;
que.push(node(1,0));
while(!que.empty()){
node s=que.top();
que.pop();
register int u=s.id,d=s.dep;
in[u]=false;
for(register int i=fir[u];i;i=edge[i].next){
register int v=edge[i].to,w=edge[i].w;
if(cost[v]>arr)
continue;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
if(!in[v]){
in[v]=true;
que.push(node(v,dis[v]));
}
}
}
}
if(dis[n]<=hp)
return true;
else
return false;
}
int main()
{
n=read(),m=read(),hp=read();
for(register int i=1;i<=n;i++)
cost[i]=read();
for(register int i=1;i<=m;i++)
{
register int a=read(),b=read(),c=read();
add(a,b,c);
add(b,a,c);
}
register bool ok=false;
if(!check(0x7fffffff))
{
printf("AFK\n");
exit(0);
}
register int l=0,r=1000000001,ans=0;
while(l<r){
register int mid=(l+r)>>1;
if(check(mid))
r=mid,ok=true,ans=mid;
else
l=mid+1;
}
if(!ok)
printf("AFK\n");
else
printf("%d\n",ans);
return 0;
}
by CreeperLordVader @ 2019-08-27 10:28:13
不开long long见祖宗