Submission #1080393

#TimeUsernameProblemLanguageResultExecution timeMemory
1080393shmaxClosing Time (IOI23_closing)C++17
8 / 100
65 ms21840 KiB
#include "closing.h"
#include "bits/stdc++.h"

using namespace std;
using i32 = int;
#define int long long
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()

template<typename T>
using vec = vector<T>;

i32 max_score(i32 N, i32 X, i32 Y, int K, std::vector<i32> U, std::vector<i32> V, std::vector<i32> W) {
    i32 ans = 0;
    priority_queue<tuple<int, int, int>, vec<tuple<int, int, int>>, greater<>> pq;
    vec<vec<pair<int, int>>> g(N);
    for (int i = 0; i < len(U); i++) {
        g[U[i]].emplace_back(V[i], W[i]);
        g[V[i]].emplace_back(U[i], W[i]);
    }

    pq.emplace(0, X, 0);
    pq.emplace(0, Y, 1);
    vec<vec<bool>> used(2, vec<bool>(N, false));
    vec<int> c(N, 0);
    while (!pq.empty()) {
        auto [cost, cur, t] = pq.top();
        pq.pop();
        if (used[t][cur]) continue;
        if (K < cost) break;
        used[t][cur] = true;
        K -= cost;
        c[cur] += cost;
        ans++;
        auto fix_queue = [&]() {
            vec<tuple<int, int, int>> objects;
            while (!pq.empty()) {
                objects.push_back(pq.top());
                pq.pop();
            }
            for (auto [a1, b1, c1]: objects) {
                if (b1 == cur)
                    a1 -= cost;
                pq.emplace(a1, b1, c1);
            }
        };
        fix_queue();


        for (auto [u, w]: g[cur]) {
            if (used[t][u]) continue;
            pq.emplace(cost + w - c[u], u, t);
        }
    }
    return ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...