dijkstra总是AFK,求调

P1462 通往奥格瑞玛的道路

EEqualIPie @ 2024-10-24 07:36:22

测试样例能过,也能过第二个测试点(非AFK),但其他测试点全是AFK,看不出来问题在哪里

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+10;
const int inf = 1e9+10;

inline int read(){
    int x=0, f=1;
    char ch = getchar();
    while(ch<'0'||ch>'9'){if(ch == '-') f=-1; ch = getchar();}
    while(ch>='0'&&ch<='9'){x = (x<<1)+(x<<3)+(ch-'0'); ch = getchar();}
    return x*f;
}

int n, m, b, f[N];
struct edge{
    int to, next, w;
} e[N];
int head[N], cnt, dis[N];
bool vis[N];

inline void add(int u, int v, int w){
    cnt++;
    e[cnt].to = v;
    e[cnt].next = head[u];
    e[cnt].w = w;
    head[u] = cnt;
}

struct node{
    int dis, pos;
    bool operator <(const node&a)const{
        return a.dis > dis;
    }
};
priority_queue<node> q;

inline bool djstra(int x){
    if(x < f[1]) return 0;
    memset(dis, 0x3f3f3f3f, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    dis[1] = 0;
    while(!q.empty()) q.pop();
    q.push((node){0, 1});
    while(!q.empty()){
        int u = q.top().pos;
        q.pop();
        if(vis[u]) continue;
        vis[u] = 1;
        for(int i=head[u]; i; i=e[i].next){
            int to = e[i].to;
            if(f[to] > x) continue;
            if(dis[u]+e[i].w < dis[to]){
                dis[to] = dis[u] + e[i].w;
                q.push((node){dis[to], to});
            }
        }
    }
    if(dis[n] >= b) return 0;
    return 1; 
}

signed main(){
    n = read(), m = read(), b = read();
    for(int i=1; i<=n; i++) f[i] = read();
    for(int u, v, c, i=1; i<=m; i++){
        u = read(), v = read(), c = read();
        add(u, v, c);
        add(v, u, c);
    }
    if(!djstra(inf)){
        printf("AFK");
        return 0;
    }
    int l=1, r=inf, mid;
    while(l<=r){
        mid = (l+r)/2;
        if(djstra(mid)) r = mid-1;
        else l = mid+1;
    }
    printf("%lld", l);
    return 0;
}

by ZMQ_Ink6556 @ 2024-10-24 08:03:44

@EEqualIPie AFK?


by tyr_04 @ 2024-10-24 08:05:06

@EEqualIPie AFK 是个什么鬼。。。


by EEqualIPie @ 2024-10-24 08:48:34

指这段代码交上去后测试点总是输出AFK @tyr_04 @ZMQ_Ink6556


by ZMQ_Ink6556 @ 2024-10-24 09:49:05

@EEqualIPie 有 AFK 评测结果吗?


|