_mumu @ 2024-05-10 14:58:36
求大佬调
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+5,M=5e4+5,F=1e9,INF=0x3f3f3f3f;
long long n,m,b,x,y,z,f[N],head[N],cnt,dis[N];
bool vis[N];
struct{
long long v,nxt,w;
}edge[M*2];
struct Tmp{
long long l,id;
Tmp(long long l,long long id):l(l),id(id){}
};
bool operator< (Tmp a,Tmp b){
return a.l<b.l;
}
priority_queue <Tmp> q;
//链式前向星
void add(long long s,long long v,long long w){
edge[cnt].v=v;
edge[cnt].w=w;
edge[cnt].nxt=head[s];
head[s]=cnt++;
}
//Dijkstra
bool check(long long x){
dis[1]=0;
vis[1]=false;
for(long long i=2;i<=n;i++){
dis[i]=INF;
vis[i]=false;
}
q.push({0,1});
while(!q.empty()){
long long p=q.top().id;
q.pop();
if(vis[p]) continue;
vis[p]=true;
for(long long i=head[p];~i;i=edge[i].nxt){
if(f[edge[i].v]>x) continue;
if(dis[p]+edge[i].w<dis[edge[i].v]){
dis[edge[i].v]=dis[p]+edge[i].w;
q.push({dis[edge[i].v],edge[i].v});//把 dis[edge[i].v]改成 edge[i].w 反而不会AFK...
}
}
}
if(dis[n]>b) return false;
return true;
}
//二分
long long find(long long l,long long r){
if(l==r) return l;
long long mid=(l+r)>>1;
if(check(mid)) return find(l,mid);
else return find(mid+1,r);
}
int main(){
//freopen("P1462_6.in","r",stdin);
memset(head,-1,sizeof(head));
scanf("%lld%lld%lld",&n,&m,&b);
for(long long i=1;i<=n;i++) scanf("%lld",&f[i]);
for(long long i=1;i<=m;i++){
scanf("%lld%lld%lld",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
if(!check(F)) printf("AFK");
else printf("%lld",find(f[1],F));
}
by _mumu @ 2024-05-11 13:02:30
结案(
bool operator< (Tmp a,Tmp b){
return a.l>b.l;
}