蒟蒻求查错,调了一个小时了

P1462 通往奥格瑞玛的道路

与我常在 @ 2019-09-24 10:21:56

贼难受

#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 10005;
const int M = 100005;

int n, m, b, num;
int f[N], dis[N], vis[N], head[N];
int to[M], val[M], next[M];

struct node {
    int d;
    int wz;
    bool operator < (const node & A) const {
        return d > A.d;
    }
};

priority_queue <node> q;

inline int Max(int x, int y) {
    return x > y ? x : y;
}

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

bool check(int x) {
    if(f[1] > f[x] || f[n] > f[x]) return false;
    memset(vis, 0, sizeof vis);
    memset(dis, 0x3f, sizeof dis);
    dis[1] = 0;
    q.push((node) {0, 1});

    while(!q.empty()) {
        node u = q.top(); q.pop();
        if(vis[u.wz]) continue;
        vis[u.wz] = 1;

        for(int i = head[u.wz]; ~i; i = next[i]) {
            if(dis[to[i]] > dis[u.wz] + val[i] && !vis[to[i]] && f[to[i]] <= f[x]) {
                dis[to[i]] = dis[u.wz] + val[i];
                q.push((node) {dis[to[i]], to[i]});
            }
        }
    }

    return b > dis[n];

}

void divi(int l, int r) {
    int ans = -1;
    while(l <= r) {
        int mid = l + r >> 1;
        if(check(mid)) ans = f[mid], r = mid - 1;
        l = mid + 1;
    }

    if(~ans) printf("%d\n", ans);
    else puts("AFK");
}

int main() {
    freopen("1.in", "r", stdin);
    scanf("%d %d %d", &n, &m, &b);

    for(int i = 1; i <= n; i ++) scanf("%d", &f[i]);

    memset(head, -1, sizeof head);
    for(int i = 1; i <= m; i ++) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        add(u, v, w);  add(v, u, w);
    }

    sort(f + 1, f + n + 1);
    int l = 1, r = n;
    divi(l, r);

    return 0;
}

by snowind @ 2019-09-30 11:04:44

@陈年风褛丶AK IOI


上一页 |