Submission #959191

#TimeUsernameProblemLanguageResultExecution timeMemory
959191kilkuwuCyberland (APIO23_cyberland)C++17
68 / 100
294 ms13120 KiB
#include "cyberland.h" #include <bits/stdc++.h> template <typename T> using PQG = std::priority_queue<T, std::vector<T>, std::greater<T>>; #ifdef LOCAL #include "template\debug.hpp" #else #define dbg(...) ; #define timer(...) ; #endif 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) { std::vector<std::vector<std::pair<int, int>>> adj(N); for (int i = 0; i < M; i++) { int u = x[i], v = y[i], w = c[i]; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } PQG<std::pair<double, int>> pq; double ans = 1e18; std::vector<double> dp(N, 1e18); pq.emplace(0, 0); dp[0] = 0; K = std::min(K, 100); while (K--) { std::vector<double> ndp(N, 1e18); PQG<std::pair<double, int>> npq; while (pq.size()) { auto [d, u] = pq.top(); pq.pop(); if (u == H) continue; if (d > dp[u]) continue; for (auto [v, w] : adj[u]) { if (arr[v] <= 1) { auto nd = (d + w) * arr[v]; if (nd < dp[v]) { dp[v] = nd; pq.emplace(nd, v); } } else { auto nd = d + w; if (nd < dp[v]) { dp[v] = nd; pq.emplace(nd, v); } nd /= 2; if (nd < ndp[v]) { ndp[v] = nd; npq.emplace(nd, v); } } } } ans = std::min(ans, dp[H]); std::swap(pq, npq); std::swap(dp, ndp); } return (ans < 1e18 ? ans : -1); } #ifdef LOCAL #include <cassert> #include <cstdio> #include <vector> int main() { int T; assert(1 == scanf("%d", &T)); while (T--){ int N,M,K,H; assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H)); std::vector<int> x(M); std::vector<int> y(M); std::vector<int> c(M); std::vector<int> arr(N); for (int i=0;i<N;i++) assert(1 == scanf("%d", &arr[i])); for (int i=0;i<M;i++) assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i])); printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr)); } } #endif
#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...