求查错,Dijkstra然后段错误

P1462 通往奥格瑞玛的道路

Wings @ 2018-08-27 17:37:48

第五点和第八个点过不去

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

const int maxn = 1e4+10;
const int maxm = 1e5+10;
const int INF = 0x3f3f3f3f;

int n, mm, h, c[maxn];

int m;
struct Edge {
    int to, next, w;
} edges[maxm];
int first[maxn];

void AddEdge(int u, int v, int w) {
    edges[++m].to = v;
    edges[m].w = w;
    edges[m].next = first[u];
    first[u] = m;
}

int l = 0, r = 0, ans, mid;

int d[maxn], vis[maxn];
struct Node {
    int u, d;
    bool operator < (const Node x) const {
        return d > x.d;
    }
};
bool Judge(int now) {
    memset(d, INF, sizeof(d));
    memset(vis, 0, sizeof(vis));
    d[1] = 0;
    priority_queue<Node> Q;
    Node temp;
    temp.u = 1, temp.d = d[1];
    Q.push(temp);
    while (!Q.empty()) {
        int u = Q.top().u;
        Q.pop();
        if (!vis[u]) {
            vis[u] = 1;
            for (int i = first[u]; i; i = edges[i].next) {
                int v = edges[i].to, w = edges[i].w;
                if (c[v] <= now && d[v] > d[u] + w) {
                    d[v] = d[u] + w;
                    temp.u = v, temp.d = d[v];
                    Q.push(temp);
                }
            }
        }
    }
    return d[n] < h;
}

int main() {
    scanf("%d%d%d", &n, &mm, &h);
    for (int i = 1; i <= n; i++) {
        scanf("%d", c + i);
        r = max(r, c[i]);
    }
    while (mm--) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        AddEdge(u, v, w);
        AddEdge(u, v, w);
    }

    while (l <= r) {
        mid = (l+r)>>1;
        if (Judge(mid)) {
            ans = mid;
            r = mid - 1;
        }
        else 
            l = mid + 1;
    }

    if (ans)
        printf("%d", ans);
    else 
        printf("AFK");
    return 0;
}


by Wings @ 2018-08-27 17:56:30

好吧我找到哪错了


by AMIRIOX無暝 @ 2022-05-14 19:57:25

所以你哪错了

我也dijkstra然后segmentation fault


|