luogu P1462 通往奥格瑞玛的道路 二分+spfa
作者:互联网
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=50000*2;
const int mod=100000000;
int n,m,b;
int e[N],ne[N],idx,h[N],w[N];
int fi[N];
const int inf=0x3f3f3f3f;
void add(int a,int b,int c)
{
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
int dist[N];
bool st[N];
int u[N];
bool check(int mid)
{
memset(dist,0x3f,sizeof dist);
memset(st,0,sizeof st);
queue<int>q;
q.push(1);
dist[1]=0;
st[1]=1;
while(q.size())
{
int t=q.front();
q.pop();
st[t]=0;
for(int i=h[t]; i!=-1; i=ne[i])
{
int j=e[i];
int w1=w[i];
if(dist[j]>dist[t]+w1&&fi[j]<=mid)
{
dist[j]=dist[t]+w1;
if(st[j]==0)
{
st[j]=1;
q.push(j);
}
}
}
}
if(dist[n]<=b)
return true;
else
return false;
}
int main()
{
memset(h,-1,sizeof h);
cin>>n>>m>>b;
for(int i=1; i<=n; i++)
{
cin>>fi[i];
u[i]=fi[i];
}
for(int i=1; i<=m; i++)
{
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
sort(u+1,u+1+n);
if(check(inf)==false)
{
cout<<"AFK"<<endl;
return 0;
}
int l=1,r=n;
while(l<r)
{
int mid=l+r>>1;
if(check(u[mid]))
r=mid;
else
l=mid+1;
}
cout<<u[l]<<endl;
return 0;
}
标签:瑞玛,dist,idx,int,luogu,mid,P1462,st,include 来源: https://www.cnblogs.com/QingyuYYYYY/p/12888148.html