Submission #781987

#TimeUsernameProblemLanguageResultExecution timeMemory
781987t6twotwoCyberland (APIO23_cyberland)C++17
100 / 100
2640 ms12212 KiB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr double inf = 1E18;
double solve(int N, int M, int K, int H, std::vector<int> U, std::vector<int> V, std::vector<int> W, std::vector<int> a) {
    K = min(K, 70);
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < M; i++) {
        adj[U[i]].emplace_back(V[i], W[i]);
        adj[V[i]].emplace_back(U[i], W[i]);
    }
    vector<bool> vis(N);
    vis[0] = 1;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        if (x == H) {
            continue;
        }
        for (auto [y, z] : adj[x]) {
            if (!vis[y]) {
                vis[y] = 1;
                q.push(y);
            }
        }
    }
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
    pq.emplace(0, 0);
    for (int i = 0; i < N; i++) {
        if (a[i] == 0 && vis[i]) {
            pq.emplace(0, i);
        }
    }
    double ans = inf;
    for (int i = K; i >= 0; i--) {
        priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> h;
        vector<bool> f(N);
        while (!pq.empty()) {
            auto [s, x] = pq.top();
            pq.pop();
            if (f[x]) {
                continue;
            }
            f[x] = 1;
            if (x == H) {
                ans = min(ans, s);
                continue;
            }
            for (auto [y, z] : adj[x]) {
                pq.emplace(s + z, y);
                if (a[y] == 2) {
                    h.emplace((s + z) / 2, y);
                }
            }
        }
        swap(h, pq);
    }
    if (ans == inf) {
        return -1;
    }
    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...