WA on #6 & #10,悬关
查看原帖
WA on #6 & #10,悬关
890257
CarlosProvo楼主2024/7/27 12:14
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int N=1e4+5;
int n,m,vis[N];
ll f[N],dis[N],b;
bool arrok=false;
struct node
{
	int to;
	ll w;
};
vector<node> G[N];
struct pq
{
	int u,w;
	friend bool operator <(pq a,pq b)
	{
		return a.w<b.w;
	}
};
bool check(int lim)
{
	priority_queue<pq> q;
	if(lim<f[1])return false;
	memset(dis,0x7f7f7f7f,sizeof dis);
	memset(vis,0,sizeof vis);
	dis[1]=0;
	q.push({1,0});
	while(q.size())
	{
		pq tmp=q.top();
		q.pop();
		if(vis[tmp.u])continue;
		vis[tmp.u]=1;
		if(b<tmp.w)continue;
		for(auto v:G[tmp.u])
		{
			if(dis[tmp.u]+v.w<dis[v.to]&&f[v.to]<=lim)
			{
				dis[v.to]=dis[tmp.u]+v.w;
				q.push({v.to,dis[v.to]});
			}
		}
	}
	return vis[n];
}
signed main()
{
	cin>>n>>m>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>f[i];
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		ll w;
		cin>>u>>v>>w;
		G[u].push_back({v,w});
		G[v].push_back({u,w});
	}
	int l=0,r=1e9+1;
	while(l<r) 
	{
		int mid=l+r>>1;
		if(check(mid))
		{
			r=mid;
			arrok=1;
		} 
		else l=mid+1;
	}
	if(arrok)cout<<r<<endl;
	else cout<<"AFK"<<endl;
	return 0;
}
2024/7/27 12:14
加载中...