91分求助!
查看原帖
91分求助!
346510
sparrowbot楼主2021/7/12 12:49
#include<bits/stdc++.h>
using namespace std;
const int ma=1000000001;
struct node{
	int ne,a,b,re;
} Q[100010];
priority_queue<int,vector<int>,greater<int> >q;
int n,m,tp,tot,ans;
int A[10010],B[10010],C[10010];
int head[10010];
bool f[10010];
void ad(int a,int b,int c){
	Q[++tot].a=a;
	Q[tot].b=b;
	Q[tot].re=c;
	Q[tot].ne=head[a];
	head[a]=tot;
	return;
}
bool check(int x){
	if(x<A[1]||x<A[n]) return false;
	for(int i=1;i<=n;i++){C[i]=ma;}
	for(int i=1;i<=n;i++){if(A[i]>x) f[i]=1;else f[i]=0;}
	C[1]=0;
	q.push(1);
	while(!q.empty()){
		int v=q.top();
		q.pop();
		if(f[v]) continue;
		f[v]=true;
		for(int i=head[v];i;i=Q[i].ne){
			if(C[Q[i].b]>Q[i].re+C[v]){
				C[Q[i].b]=Q[i].re+C[v];
				q.push(Q[i].b);
			}
		}
	}
	if(C[n]<=tp) return true;
	else return false;
}
int main(){
	cin>>n>>m>>tp;
	for(int i=1;i<=n;i++){
		cin>>A[i],B[i]=A[i];
	}
	for(int i=1;i<=m;i++){
		int a,b,re;
		cin>>a>>b>>re;
		if(a==b) continue;
		ad(a,b,re);
		ad(b,a,re);
	}
	sort(B+1,B+n+1);
	if(!check(B[n])){
		cout<<"AFK\n";
		return 0;
	}
	int l=1,r=n,mid;
	ans=B[n];
	while(l<=r){
		mid=(l+r)/2;
		if(check(B[mid])){
//	cout<<"F**K!\n";
			ans=B[mid];
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	cout<<ans<<endl;
	return 0;
}
2021/7/12 12:49
加载中...