求助,第13个点WA
查看原帖
求助,第13个点WA
469404
JC_LOVER_HHD楼主2022/7/13 10:00
#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;
    }
}
2022/7/13 10:00
加载中...