为什么92?
查看原帖
为什么92?
741732
small_Dongpo楼主2024/7/4 18:56

悬关,不要发自己的代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>
#define r register
using namespace std;

typedef long long l;
l n, m, t, d[305];
bool vis[305];

char inbuf[1024], *st=inbuf, *en=inbuf, outbuf[1048576], *outptr=outbuf;
#define g() (((st == en) && (en = (st = inbuf) + fread(inbuf, 1, 1024, stdin))), (st==en)? EOF : *(st++))
#define p(x) (*(outptr++) = (x))

inline l read() {
    r l x(0);
    r char ch(g());
    for (; !isdigit(ch); ch = g());
    for (; isdigit(ch); ch = g()) x = (x << 1) + (x << 3) + (ch ^ 48);
    return x;
}

inline void print(register const l &x) {
    if (9 - x >> 63) {
        print(x / 10);
    }
    p(x % 10 + 48);
}

struct Edge {
    l y, z;
};

vector<Edge> v[100005];

struct Node {
    l i, d;
    bool operator<(const Node & a) const {
        return a.d - d >> 63;
    }
};

inline l dij(r l a, r l b) {
    fill(d + 1, d + n + 1, 2e9);
    priority_queue<Node> q;
    d[a] = 0;
    q.push({a, d[a]});
    while (!q.empty()) {
        r l x = q.top().i;
        q.pop();
        if (vis[x] == 1) continue;
        if (x == b) return d[x];
        vis[x] = 1;
        for (r Edge i : v[x]) {
            if (max(d[x], i.z) - d[i.y] >> 63) {
                d[i.y] = max(d[x], i.z);
                q.push({i.y, d[i.y]});
            }
        }
    }
    return -1;
}

int main() {
    n = read(), m = read(), t = read();
    for (r l i = 1; i <= m; ++i) {
        r const l x(read()), y(read()), z(read());
        v[x].push_back({y, z});
    }
    for (r l i = 1; i <= t; ++i) {
        fill(vis + 1, vis + n + 1, 0);
        fill(d + 1, d + n + 1, 2e9);
        r l const a(read()), b(read());
        r l const ans(dij(a, b));
        if (-ans >> 63) print(ans);
        else {p(45);p(49);}
        p(10);
    }
    fwrite(outbuf, outptr - outbuf, 1, stdout);
    return 0;
}
2024/7/4 18:56
加载中...