QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589587#5073. Elden RingnekotorowoWA 196ms3796kbC++203.3kb2024-09-25 18:45:532024-09-25 18:45:56

Judging History

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

  • [2024-09-25 18:45:56]
  • 评测
  • 测评结果:WA
  • 用时:196ms
  • 内存:3796kb
  • [2024-09-25 18:45:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second

using ll = long long int;
using ld = long double;

const int INF = 1000000007;
const ll INF64 = 1000000000000000003LL;
const int CUTE_LOGN = 17;

pair<vector<bool>, ll> all_reachable(const vector<vector<int>>& g, const vector<ll>& s, ll d) {
    ll curs = s[0];
    int n = g.size();
    vector<bool> used(n, false), reachable(n, false);
    set<pair<ll, int>> h;

    used[0] = true;
    reachable[0] = true;
    h.insert({0, 0});

    while (!h.empty()) {
        auto [sv, v] = *begin(h);
        h.erase(begin(h));

        if (curs <= sv) {
            break;
        }
        reachable[v] = true;

        for (int u : g[v]) {
            if (!used[u]) {
                h.insert({s[u], u});
                used[u] = true;
            }
        }
        curs += d;
    }

    return {reachable, curs};
}

void solve() {
    int n, m;
    vector<ll> dist, s;
    vector<vector<int>> g;
    set<pair<ll, int>> h;
    ll a, b;

    cin >> n >> m >> a >> b;

    g.resize(n);
    for (int i = 0; i < m; i++) {
        int v, u;

        cin >> v >> u;
        v--, u--;

        g[v].push_back(u);
        g[u].push_back(v);
    }
    s.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        if (i > 0) {
            s[i] += b;
        }
    }

    if (a <= b) {
        dist.resize(n, INF64);
        dist[0] = 0;
        h.insert({0, 0});
        while (!h.empty()) {
            auto [d, v] = *begin(h);
            h.erase(begin(h));

            if (dist[v] != d) { continue; }

            for (int u : g[v]) {
                if (s[u] < s[0] + d * (a - b) && dist[u] > dist[v] + 1) {
                    dist[u] = dist[v] + 1;
                    h.insert({dist[u], u});
                }
            }
        }
        if (dist[n - 1] == INF64) {
            cout << -1 << '\n';
        } else {
            cout << dist[n - 1] << '\n';
        }
        return ;
    }

    auto [reachable, maxs] = all_reachable(g, s, a - b);
    if (reachable[n - 1] == false) {
        cout << -1 << '\n';
        return ;
    }

    dist.resize(n, INF64);
    dist[0] = 0;
    h.insert({0, 0});
    while (!h.empty()) {
        auto [d, v] = *begin(h);
        h.erase(begin(h));

        if (dist[v] != d) { continue; }

        for (int u : g[v]) {
            if (s[u] < s[0] + d * (a - b)) {
                if (dist[u] > dist[v] + 1) {
                    dist[u] = dist[v] + 1;
                    h.insert({dist[u], u});
                }
            } else {
                ll k = 1 + (s[u] - s[0] + 1) / (a - b);
                if (s[u] < maxs && dist[u] > max(dist[v] + 1, k)) {
                    dist[u] = max(dist[v] + 1, k);
                    h.insert({dist[u], u});
                }
            }
        }
    }
    if (dist[n - 1] == INF64) {
        cout << -1 << '\n';
    } else {
        cout << dist[n - 1] << '\n';
    }
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;

    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3796kb

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:

2
4

result:

ok 2 number(s): "2 4"

Test #2:

score: -100
Wrong Answer
time: 196ms
memory: 3612kb

input:

100000
6 10 107812 105568
6 5
3 6
4 6
4 2
5 1
5 6
4 5
1 3
1 2
2 5
124065 140875 29890 80077 116532 35394
9 10 82107 88302
1 2
2 3
5 3
5 1
1 4
9 6
3 5
8 2
5 6
7 5
22670 3735 33660 92823 139960 89319 83335 158330 117349
6 10 181257 173221
5 3
3 4
3 1
5 1
2 1
3 6
3 1
6 2
3 6
4 3
76902 46253 123092 2661...

output:

-1
-1
-1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
3
-1
1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-...

result:

wrong answer 22nd numbers differ - expected: '2', found: '1'