蒟蒻求助,玄关求条,100分wa#12-—#13
查看原帖
蒟蒻求助,玄关求条,100分wa#12-—#13
855557
conyon楼主2025/1/23 16:08
#include <bits/stdc++.h>
using LL=long long;
using namespace std; 
#define INF 0x7fffffff
const int N=1e4+5;
LL f[N],dis[N];
int n,m,b;
vector<pair<int,int> >G[N];
struct heap{
	int id,d;
	bool operator <(const heap& rhs)const{
		return rhs.d<d;
	}
};
bool check(LL x){
	priority_queue<heap> q;
	for(int i=1;i<=n;i++) dis[i]=1e9;
	q.push((heap){1,0});
	dis[1]=0;
	while(!q.empty()){
   		auto xx=q.top();
		q.pop();
		int u=xx.id;
		if(dis[u]!=xx.d)continue;
		for(auto xx:G[u]){
			int v=xx.first,w=xx.second;
			if(f[v]<=x&&dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				q.push((heap){v,dis[v]});
			}
		}	   
	}
	return dis[n]<b;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	
	cin>>n>>m>>b;
	for(int i=1;i<=n;i++){
		cin>>f[i];
	}
	
	for(int i=1;i<=m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		G[u].push_back({v,w});
		G[v].push_back({u,w});
	}
	
	LL l=0,r=1e18,ans=0;
	while(l<=r){
		LL mid=(l+r)>>1;
		if(check(mid)){
			r=mid-1;
			ans=mid;
		}else l=mid+1;
	}
	if(ans==0)cout<<"AFK";
	else cout<<ans;
	return 0;
}

2025/1/23 16:08
加载中...