求助 二分 WA了#12 #13
查看原帖
求助 二分 WA了#12 #13
494992
underline__jian楼主2022/3/3 22:04
#include<iostream>
#include<algorithm>
#include<queue>
#define re register
using namespace std;
const int N=5000010,INF=0x3f3f3f3f;
long long n,m,b,c[N],cc[N],dis[N],ans;
bool vis[N],flag[N];
priority_queue<pair<long,long> >que;
struct node{
	int to,head,nxt;
	long long v;
}e[N];
int tot;
inline void add(long long x,long long y,long long z){
	e[++tot].to=y;
	e[tot].v=z;
	e[tot].nxt=e[x].head;
	e[x].head=tot;
}
inline void dijkstra(){
	for(re int i=1;i<=n;i++){
		vis[i]=false;
		dis[i]=INF;
	}
	dis[1]=0;
	que.push(make_pair(0,1));
	while(!que.empty()){
		int x=que.top().second;
		que.pop();
		if(vis[x]) continue;
		vis[x]=true;
		for(re int i=e[x].head;i;i=e[i].nxt){
			int v=e[i].to;
			if(dis[v]>dis[x]+e[i].v&&flag[x]==0&&flag[v]==0){
				dis[v]=dis[x]+e[i].v;
				que.push(make_pair(-dis[v],v));
			}
		}
	}
}
inline bool check(long long x){
	for(re int i=1;i<=n;i++) flag[i]=false;
	for(re int i=1;i<=n;i++) if(c[i]>x) flag[i]=true;
	dijkstra();
	if(dis[n]==INF||dis[n]>=b) return false;
	return true;
}
inline long long read(){
	long long x=0,y=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') y=-y;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*y;
}
int main(){
	n=read(),m=read(),b=read();
	for(re int i=1;i<=n;i++){
		c[i]=read();
		cc[i]=c[i];
	}
	for(re int i=1;i<=m;i++){
		long long x=read(),y=read(),z=read();
		add(x,y,z);
		add(y,x,z);
	}
	dijkstra();
	if(dis[n]==INF||dis[n]>=b){
		printf("AFK");
		exit(0);
	}
	sort(cc+1,cc+1+n);
	ans=cc[n];
	int l=1,r=n;
	while(l<=r){
		long long mid=(l+r)>>1;
		if(check(cc[mid])==true){
			ans=cc[mid];
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%lld",ans);
	return 0;
}
2022/3/3 22:04
加载中...