Submission #1069698

#TimeUsernameProblemLanguageResultExecution timeMemory
1069698thangdz2k7Cyberland (APIO23_cyberland)C++17
100 / 100
1559 ms10588 KiB
#include <bits/stdc++.h> #define db double using namespace std; const db inf = 1e18; const db mid = 2.0; db solve(int N, int M, int K, int H, vector <int> x, vector <int> y, vector <int> c, vector <int> arr){ K = min(K, 100); vector <vector <int>> adj(N); for (int i = 0; i < M; ++ i) adj[x[i]].push_back(i), adj[y[i]].push_back(i); vector <db> dp(N, inf); dp[0] = 0.0; db ans = inf; for (int loops = 0; loops <= K; ++ loops){ priority_queue <pair <db, int>> qu; vector <db> rd(N, inf); for (int u = 0; u < N; ++ u){ if (dp[u] == inf || (u > 0 && arr[u] == 1)) continue; if (arr[u] == 0) rd[u] = 0.0; qu.push({-dp[u] / mid, u}); } while (qu.size()){ auto [du, u] = qu.top(); qu.pop(); du = -du; if (u == H) continue; for (int id : adj[u]){ int v = x[id] ^ y[id] ^ u; if (rd[v] > du + c[id]){ if (arr[v] == 0) rd[v] = 0; else rd[v] = du + c[id]; qu.push({-rd[v], v}); } } } if (!loops && rd[H] == inf) break; dp = rd; ans = min(ans, dp[H]); } if (ans == inf) return -1; return ans; } //void solve(){ // int N, M, K; cin >> N >> M >> K; // int H; cin >> H; // vector <int> arr(N); for (int i = 0; i < N; ++ i) cin >> arr[i]; // vector <int> x(M), y(M), z(M); for (int i = 0; i < M; ++ i) cin >> x[i] >> y[i] >> z[i]; // cout << fixed << setprecision(10) << solve(N, M, K, H, x, y, z, arr) << '\n'; //} // //int main(){ // freopen("cyberland.inp", "r", stdin); // freopen("cyberland.out", "w", stdout); //// ios_base::sync_with_stdio(0); //// cin.tie(0); //// cout.tie(0); // // int t = 1; // while (t --) solve(); // // return 0; //}
#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...