Phill @ 2024-02-06 20:13:32
WA on #8 输出了AFK,应输出7...
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
const int inf=0x3f3f3f3f;
int n,m;
long long b;
int cost[maxn];
long long dis[maxn];
vector<pair<int,int> > e[maxn*5];
queue<int> q;
bool solve(int x){
bool vis[maxn]={0};
if(cost[1]>x) return false;
for(int i=1;i<=n;i++) dis[i]=inf;
dis[1]=0,vis[1]=1;q.push(1);
while(!q.empty())
{
int u=q.front();q.pop();
vis[u]=1;
for(int i=0;i<(int)e[u].size();i++)
{
int v=e[u][i].first;
if(dis[v]>dis[u]+e[u][i].second){
if(!vis[v]&&cost[v]<=x){
dis[v]=dis[u]+e[u][i].second;
q.push(v),vis[v]=1;
}
}
}
}
if(dis[n]<=b) return true;
else return false;
}
int main(){
// freopen("P1462_8.in","r",stdin);
cin>>n>>m>>b;
int l=0,r=0;
for(int i=1;i<=n;i++) cin>>cost[i],r=max(r,cost[i]);
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
e[u].push_back(make_pair(v,w));
e[v].push_back(make_pair(u,w));
}
if(!solve(inf)){cout<<"AFK";return 0;}
while(l<=r)//二分枚举交费最多的一次
{
int mid=(l+r)/2;
// cout<<l<<" "<<r<<" "<<mid<<" "<<spfa(mid)<<endl;
if(solve(mid)) r=mid-1;
else l=mid+1;
}
cout<<l;
}
by xirunzhao @ 2024-02-06 20:25:45
我给你精神上的支持
by Soaring_light @ 2024-02-07 08:32:39
首先,你用spfa的勇气,值得我赞赏
by Rosick @ 2024-03-13 18:25:07
@Phill 找到错了吗,我也这样