WA on #13,100pts求条玄2关

P1462 通往奥格瑞玛的道路

CP_2309 @ 2024-07-22 08:46:01

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
struct node
{
    int to,nex,w;
}e[N*10];
int head[N*10],cnt,dis[N];
int f[N],n,m,b;
bool vis[N];
void add(int x,int y,int z)
{
    cnt++;
    e[cnt].to=y;
    e[cnt].w=z;
    e[cnt].nex=head[x];
    head[x]=cnt;
}
priority_queue<pair<int,int> >q; 
int dij(int k)
{
    while (q.size()) q.pop();
    for (int i=1;i<=n;++i)
    {
        dis[i]=1e18/3;
        vis[i]=0;
    }
    q.push(make_pair(0,1));
    dis[1]=0;
    while(!q.empty())
    {
        int x=q.top().second;
        q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=head[x];i;i=e[i].nex)
        {
            int y=e[i].to;
            if (f[y]>k) continue;
            if(dis[x]+e[i].w<dis[y])
            {
                dis[y]=dis[x]+e[i].w;
                q.push(make_pair(-dis[y],y));
            }
        }
    }
    return (dis[n]>b);
}
signed main()
{
    cin >> n >> m >> b;
    int l=1e9,r=-1;
    for (int i=1;i<=n;++i)
    {
        cin >> f[i];
        l=min(l,f[i]);
        r=max(r,f[i]); 
    }
    for (int i=1;i<=m;++i)
    {
        int x,y,z;
        cin >> x >> y >> z;
        add(x,y,z);
        add(y,x,z);
    }
    while (l<r)
    {
        int mid=(l+r)/2;
        if (dij(mid)) 
        {   
            l=mid+1;
        } 
        else 
        {
            r=mid;
        }
    }
    if (dij(l))
    {
        puts("AFK");
    }
    else cout << l;
    return 0;
}
/*
5 5 6
10
5
2
10
0
1 2 4
2 5 2
2 4 1
3 5 2
5 5 1

10
*/

by chen_z @ 2024-07-22 11:57:42

@CP_2309 没有判断f[1]与mid大小关系


by chen_z @ 2024-07-22 11:59:51

@CP_2309 在dijkstra那个函数第一句加上

if(f[1]>k)return 1;

就A了


by CP_2309 @ 2024-07-29 15:35:42

@chen_z 已关


|