求助,第13个点WA

P1462 通往奥格瑞玛的道路

JC_LOVER_HHD @ 2022-07-13 10:00:20

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int MAX_N=10010;
const int INF=0x7fffffff;
struct edge{
    int to;
    int cost;
};
typedef pair<int ,int > p;
int n,m,b;
long long f[MAX_N];
vector <edge> G[MAX_N];
long long d[MAX_N];
bool dijkstra(long long );
int main()
{
    scanf("%d%d%d",&n,&m,&b);
    for(register int i=1;i<=n;i++)
    {
        scanf("%lld",&f[i]);
    }
    for(register int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        G[u].push_back((edge){v,w});
        G[v].push_back((edge){u,w});
    }
    if(dijkstra(1e9)==false)
    {
        printf("AFK");
        return 0;
    }
    long long l=INF,r=-INF;
    for(register int i=1;i<=n;i++)
    {
        l=min(l,f[i]);
        r=max(r,f[i]);
    }
    while(l<=r)
    {
        long long mid=(r-l)/2+l;
        if(dijkstra(mid)==false)
        {
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }
    }
    printf("%lld",l);
    return 0;
}
bool dijkstra(long long x)
{
    priority_queue<p ,vector<p> ,greater<p> > que;
    fill(d+1,d+n+1,INF);
    d[1]=0;
    que.push(p(0,1));
    while(!que.empty())
    {
        p t=que.top();
        que.pop();
        int v=t.second;
        if(d[v]<t.first)
        {
            continue;
        }
        for(register int i=0;i<G[v].size();i++)
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost&&f[e.to]<=x)
            {
                d[e.to]=d[v]+e.cost;
                que.push(p(d[e.to],e.to));
            }
        }
    }
    if(d[n]>b)
    {
        return false;
    }
    else
    {
        return true;
    }
}

by HopeAndLizz @ 2022-07-15 23:40:39

需判断起点1是否小于等于x


by Otue @ 2022-07-21 15:44:28

@hopeyuxiaoli 谢谢大佬,调了15分钟的错误终于找出来了...


by JC_LOVER_HHD @ 2022-07-23 19:02:08

@hopeyuxiaoli 非常感谢


|