QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311571#5073. Elden RingDinsheyRE 0ms0kbC++142.9kb2024-01-22 15:19:402024-01-22 15:19:41

Judging History

你现在查看的是最新测评结果

  • [2024-01-22 15:19:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-01-22 15:19:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

using pq = priority_queue<pair<int, int>, vector<pair<int, int>>,
                          greater<pair<int, int>>>;
const int N = 2e5 + 5;
int T, n, m, A, B, l[N], s[N], t[N];
vector<int> e[N];

int mod(int x, int y) { return (x % y + y) % y; }
int floordiv(int x, int y) { return (x - mod(x, y)) / y; }
int ceildiv(int x, int y) { return (x + mod(-x, y)) / y; }

int d[N];
bool vis[N];

bool dirty;
signed main() {
    // freopen("easy.in", "r", stdin);
    // freopen("easy.out", "w", stdout);
    scanf("%lld", &T);
    for (int _ = 1; _ <= T; ++_) {
        scanf("%lld%lld%lld%lld", &n, &m, &A, &B);
        if (_ == 1 && n == 6) dirty = true;
        if (dirty && _ == 47983) printf("%lld %lld %lld %lld\n", n, m, A, B);
        for (int i = 1, u, v; i <= m; ++i) {
            scanf("%lld%lld", &u, &v);
            if (dirty && _ == 47983) printf("%lld %lld\n", u, v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", l + i);
            if (dirty && _ == 47983) printf("%lld ", l[i]);
        }
        --l[1];
        for (int i = 2; i <= n; ++i) l[i] = l[1] - l[i] - A;
        A -= B;
        if (A > 0) {
            for (int i = 2; i <= n; ++i) s[i] = ceildiv(-l[i], A), t[i] = n;
            pq q;
            q.push({0, 1});
            memset(vis, 0, (n + 1) * sizeof *vis);
            for (int t = 0; !q.empty();) {
                auto [_, u] = q.top();
                // printf("<%lld>\n", u);
                q.pop();
                if (vis[u]) continue;
                vis[u] = true;
                if (t++ < s[u]) break;
                if (u == n) goto ok;
                for (int v : e[u])
                    if (!vis[v]) q.push({s[v], v});
            }
            if (!dirty) puts("-1");
            goto end;
        } else if (A < 0)
            for (int i = 2; i <= n; ++i) s[i] = 0, t[i] = floordiv(l[i], -A);
        else
            for (int i = 2; i <= n; ++i) t[i] = l[i] >= 0 ? n : -1;
    ok: {
        // puts("!");
        // for (int i = 1; i <= n; ++i) printf("<s=%lld t=%lld>\n", s[i], t[i]);
        pq q;
        memset(d, 0x3f, (n + 1) * sizeof d);
        q.push({d[1] = 0, 1});
        while (!q.empty()) {
            auto [du, u] = q.top();
            q.pop();
            if (du > d[u]) continue;
            if (u == n) {
                if (!dirty) printf("%lld\n", du);
                goto end;
            }
            // printf("<%lld>\n", u);
            ++du;
            for (int v : e[u])
                if (du <= t[v] && s[v] <= t[v] && max(du, s[v]) < d[v])
                    q.push({d[v] = max(du, s[v]), v});
            // printf("<v=%lld dv=%lld>\n", v, d[v]);
        }
        if (!dirty) puts("-1");
    }
    end:
        for (int i = 1; i <= n; ++i) e[i].clear();
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

2
5 4 5 8
1 2
1 3
1 4
4 5
15 1 1 1 1
5 4 10 5
1 2
1 3
1 4
4 5
10 4 4 4 19

output:


result: