刚学OI(真),国庆求助

P1462 通往奥格瑞玛的道路

touristX @ 2018-10-01 10:47:38

求教WA on #8,输出了AFK,求dalao找错(码风不好见谅)

#include <bits/stdc++.h>
#define reg register
using namespace std;
typedef long long LL;
const int N = 20005;
const int M = 100005;
const LL inf = 1e16;
LL cost[N], kil[M], dis[N], le = inf, ri, mid;
int n, m, b, cnt, head[M], nxt[M], to[M];
bool vis[N], wr;

inline LL read() {
    reg char c; LL x = 0;
    for (c = getchar(); c < '0'|| c > '9'; c = getchar());
    for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x;
}

struct cmp { bool operator () (int a,int b) { return dis[a] > dis[b]; } };

priority_queue < LL, vector < LL >, cmp > q;

inline void Add_Edge (int u, int v, LL w) { to[++cnt] = v, kil[cnt] = w, nxt[cnt] = head[u], head[u] = cnt; }

inline void done () { for (reg int i = 2; i <= n; ++i) dis[i] = inf, memset(vis, 0, sizeof vis); }

int main() {
    n = read(), m = read(), b = read();
    for (reg int i = 1; i <= n; ++i)
        cost[i] = read(), ri = max (ri, cost[i]), le = min (le, cost[i]);
    for (reg int i = 1, u, v, w; i <= m; ++i)
        u = read(), v = read(), w = read(), Add_Edge(u, v, w), Add_Edge(v, u, w);
    ++ri;
    while (le <= ri) {
        mid = le + ri >> 1, done(), q.push(1);
        while (!q.empty()) {
            LL p = q.top();
            q.pop(), vis[p] = 0;
            for (reg int i = head[p]; i; i = nxt[i])
                if (cost[to[i]] <= mid && dis[p] + kil[to[i]] < dis[to[i]]) {
                    dis[to[i]] = dis[p] + kil[to[i]];
                    if (!vis[to[i]]) q.push(to[i]), vis[to[i]] = 1;
                }
        }
        if (dis[n] >= b) le = mid + 1;
        else ri = mid - 1, wr = 1;
    }
    if(!wr) puts ("AFK");
    else cout << le;
    return 0;
}

by 览遍千秋 @ 2018-10-01 10:48:25

刚学OI系列...


by Jaanai @ 2018-10-01 10:49:54

魔鬼


by 桜Sakura @ 2018-10-01 10:51:15

刚学OI就做蓝题,QWQ


by touristX @ 2018-10-01 10:51:25

给点建设性意见啊QWQ


by Jaanai @ 2018-10-01 10:53:30

他的大号


by touristX @ 2018-10-01 10:54:17

@jccretsehc 假的


by aoweiyin @ 2018-10-01 10:55:09

个人认为码风还行^_^


by 913887524gsd @ 2018-10-01 10:55:19

刚学OI就会图论,还会快读

感觉lz的二分答案这一块貌似有锅


by aoweiyin @ 2018-10-01 10:55:58

@touristX 您等下可以水一下双倍经验 —— 收费站


by aoweiyin @ 2018-10-01 10:58:17

@touristX 我随便提几点您看注意了没有: 血量不能0; 第一个点要判一下;

如果都没有的话,就……逃吧…… ╮(╯▽╰)╭


| 下一页