Submission #749157

#TimeUsernameProblemLanguageResultExecution timeMemory
749157gun_ganCyberland (APIO23_cyberland)C++17
97 / 100
3074 ms16644 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; typedef long long ll; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<vector<pair<int,int>>> g(N); for(int i = 0; i < M; i++) { g[x[i]].push_back({y[i], c[i]}); g[y[i]].push_back({x[i], c[i]}); } priority_queue<pair<double,int>> pq; vector<double> dd(N, 1e18); { dd[0] = 0; pq.push({0, 0}); while(!pq.empty()) { auto [x, v] = pq.top(); pq.pop(); x = -x; if(dd[v] < x) continue; for(auto [u, w] : g[v]) { if(dd[u] > x + w && u != H) { dd[u] = x + w; pq.push({-dd[u], u}); } } } } vector<array<double, 2>> d(N, {1e18, 1e18}); arr[0] = 0; for(int i = 0; i < N; i++) if(!arr[i] && dd[i] == 1e18) arr[i] = 1; { for(int i = 0; i < N; i++) { if(!arr[i] && dd[i] != 1e18) { d[i][1] = 0; pq.push({0, i}); } } while(!pq.empty()) { auto [x, v] = pq.top(); pq.pop(); x = -x; if(d[v][1] < x) continue; for(auto [u, w] : g[v]) { if(d[u][1] > x + w && u != H) { d[u][1] = x + w; pq.push({-d[u][1], u}); } } } } double res = 1e18; for(auto [u, w] : g[H]) { res = min(res, d[u][1] + w); } for(int k = 1; k <= min(100, K); k++) { vector<array<double,2>> nd(N, {1e18, 1e18}); priority_queue<pair<double,pair<int, int>>> pq; for(int i = 0; i < N; i++) { nd[i][0] = min(d[i][0], d[i][1]); if(arr[i] == 2 && nd[i][0] != 1e18) { nd[i][0] = min(nd[i][0], d[i][1] / 2); } if(nd[i][0] != 1e18) pq.push({-nd[i][0], {i, 0}}); } while(!pq.empty()) { auto [x, p] = pq.top(); auto [v, c] = p; pq.pop(); x = -x; if(nd[v][c] < x) continue; for(auto [u, w] : g[v]) { if(nd[u][c | 1] > x + w && u != H) { nd[u][c | 1] = x + w; pq.push({-nd[u][c | 1], {u, c | 1}}); } } } swap(nd, d); for(auto [u, w] : g[H]) { res = min(res, min(d[u][0], d[u][1]) + w); } } if(res == 1e18) res = -1; return res; } // int main() { // cin.tie(0); ios_base::sync_with_stdio(0); // // cout << fixed << setprecision(1) << solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1}) << '\n'; // // cout << fixed << setprecision(1) << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << '\n'; // cout << fixed << setprecision(1) << solve(4, 3, 3, 3, {0, 1, 2}, {1, 2, 3}, {11, 1, 10}, {1, 1, 2, 1}) << '\n'; // }
#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...