wa#13 求最短路径加了判断起点和Mid后全WA,本地跑出来是对的
查看原帖
wa#13 求最短路径加了判断起点和Mid后全WA,本地跑出来是对的
995390
codePanclA楼主2023/8/10 14:04
#include <math.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define ll long long
#define INF 1000000001
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
const int N=110000;
struct node{
	ll num;
	ll dis;
	bool operator<(const node& b)const{
	return dis>b.dis;
	}
}; 
priority_queue<node> q;
struct {
	ll nxt,to,w;
}edge[N];
ll cnt,head[N],vis[N];
ll n,m;
ll b,dis[N],f[N];
void add(ll a,ll b,ll c){
	edge[++cnt].to=b;
	edge[cnt].w=c;
	edge[cnt].nxt=head[a];
	head[a]=cnt;
}
bool dijkstra(ll x){
	for(int i=1;i<=11000;i++){
		dis[i]=INF;
		vis[i]=0;
	}
	dis[1]=0;
	if(f[1]>x){
		return false;
	}
	while(!q.empty()) q.pop();
	q.push({1,dis[1]});
	while(!q.empty()){
		node t=q.top();
		ll u=t.num;
		ll d=t.dis;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(f[v]>x) continue;
			if(dis[u]+edge[i].w<=dis[v]){
			dis[v]=dis[u]+edge[i].w;
			q.push({v,dis[v]});
			}
		}
	} 
	if(dis[n]>b) return false;
	return true;
}
int main(int argc, char** argv) {
	cin>>n>>m>>b;
	ll l,r;
	for(int i=1;i<=n;i++){
		cin>>f[i];
		r=max(r,f[i]);
	}
	l=f[1];
	cout<<l;
	for(int i=1;i<=m;i++){
		ll a,b,c;
		cin>>a>>b>>c;
		add(a,b,c);
		add(b,a,c);
	}
	if(!dijkstra(INF)){
		cout<<"AFK";
		return 0;
	}
	while(l+1<r){
		ll mid=(l+r)/2;
		if(dijkstra(mid)){
			r=mid;
		}else l=mid;
	}
	cout<<r;
	return 0;
}
2023/8/10 14:04
加载中...