kimi123 @ 2024-08-10 10:07:15
就是一个正常的二分+dij。。
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int B=1e9+3,N=5e4+7;
int n,m,b;
struct node{
int val,bh;
};
vector <pair<int,int> > vc[N];
int dis[N],c[N],f[N];
bool vis[N];
priority_queue <node> q;
bool operator<(node a,node b){
return a.val>b.val;
}
bool check(int mane){
memset(vis,0,sizeof(vis));
memset(dis,0x7f,sizeof(dis));
dis[1]=0; q.push({0,1});
if(f[1]>mane) return false;
while(!q.empty()){
int x=q.top().bh; q.pop();
if(f[x]>mane) return false;
if(vis[x]) continue;
vis[x]=1;
for(auto to:vc[x]){
if(dis[x]+to.se<=dis[to.fi]&&f[to.fi]<=mane){
dis[to.fi]=dis[x]+to.se;
q.push({dis[to.fi],to.fi});
}
}
}
if(dis[n]<=b) return true;
return false;
}
signed main(){
cin>>n>>m>>b;
for(int i=1;i<=n;i++){
cin>>f[i];
}
for(int i=1;i<=n;i++){
int a,b; cin>>a>>b>>c[i];
if(a==b) continue;
vc[a].push_back(make_pair(b,c[i]));
vc[b].push_back(make_pair(a,c[i]));
}
if(check(B)==false) {cout<<"AFK";return 0;}
int l=0,r=B;
while(l<r){
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l;
return 0;
}
by StrangeSolver @ 2024-08-10 11:00:58
代码改好发你了,好像是优先队列炸了,二分答案的r也不用B了
by kimi123 @ 2024-08-10 11:04:13
%%%