Submission #963561

#TimeUsernameProblemLanguageResultExecution timeMemory
963561IBoryCyberland (APIO23_cyberland)C++17
49 / 100
194 ms10748 KiB
#include "cyberland.h" #include <bits/stdc++.h> #define pii pair<ll, ll> typedef long long ll; using namespace std; const int MAX = 100007; vector<pii> G[MAX]; bool V[MAX]; ll D[MAX], LD[MAX]; double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) { for (int i = 0; i < N; ++i) G[i].clear(); for (int i = 0; i < M; ++i) { G[x[i]].emplace_back(y[i], c[i]); G[y[i]].emplace_back(x[i], c[i]); } int ok = 0; memset(V, 0, sizeof(V)); V[0] = 1; queue<int> Q; Q.push(0); while (!Q.empty()) { int cur = Q.front(); Q.pop(); for (auto [next, _] : G[cur]) { if (V[next]) continue; if (next == H) { ok = 1; continue; } V[next] = 1; Q.push(next); } } if (!ok) return -1; memset(D, 0x3f, sizeof(D)); priority_queue<pii, vector<pii>, greater<pii>> PQ; for (int i = 0; i < N; ++i) { if (!V[i] || (i && arr[i])) continue; PQ.emplace(D[i] = 0, i); } while (!PQ.empty()) { auto [cd, cur] = PQ.top(); PQ.pop(); if (cd > D[cur]) continue; for (auto [next, nd] : G[cur]) { if (D[next] <= cd + nd) continue; D[next] = cd + nd; if (next == H) continue; PQ.emplace(D[next], next); } } memset(LD, 0x3f, sizeof(LD)); PQ.emplace(LD[H] = 0, H); while (!PQ.empty()) { auto [cd, cur] = PQ.top(); PQ.pop(); if (cd > LD[cur]) continue; for (auto [next, nd] : G[cur]) { if (LD[next] <= cd + nd) continue; PQ.emplace(LD[next] = cd + nd, next); } } double ans = D[H]; if (K) { for (int i = 0; i < N; ++i) { if (arr[i] != 2 || !V[i]) continue; ll a = D[i], b = LD[i], c = 1e18; for (auto [next, nd] : G[i]) { if (next == H) continue; c = min(c, nd); } double cd = (double)a / 2.0, t = cd; for (int k = 1; k < min(100, K); ++k) { t = (t + 2LL * c) / 2.0; cd = min(cd, t); } cd += (double)b; ans = min(ans, cd); } } 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...