Submission #957545

#TimeUsernameProblemLanguageResultExecution timeMemory
957545abczzCyberland (APIO23_cyberland)C++17
0 / 100
3079 ms74944 KiB
#include "cyberland.h" #include <iostream> #include <vector> #include <queue> #include <array> #define ll long long #define ld long double using namespace std; vector <array<ll, 2>> adj[100000]; ll h; bool visited[100000]; priority_queue<array<ld, 3>, vector<array<ld, 3>>, greater<array<ld, 3>>> pq; ld dp[100000][61]; void dfs(ll u) { visited[u] = 1; for (auto [v, x] : adj[u]) { if (v != h && !visited[v]) { dfs(v); } } } 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) { K = min(K, 60), h = H; for (int i=0; i<N; ++i) { for (int j=0; j<=K; ++j) { dp[i][j] = 1e18; } } for (int i=0; i<M; ++i) { adj[x[i]].push_back({y[i], c[i]}); adj[y[i]].push_back({x[i], c[i]}); } dfs(0); for (int i=0; i<N; ++i) { if (visited[i] && (!arr[i] || !i)) { dp[i][K] = 0; pq.push({0, (ld)i, (ld)K}); } } while (!pq.empty()) { auto [w, du, dy] = pq.top(); pq.pop(); ll u = (ll)du, y = (ll)dy; if (dp[u][y] != w || u == H) continue; for (auto [v, x] : adj[u]) { if (dp[v][y] > w+x) { dp[v][y] = w+x; pq.push({dp[v][y], (ld)v, (ld)y}); } else if (y && arr[v] == 2 && dp[v][y-1] > (w+(ld)x)/2) { dp[v][y-1] = (w+(ld)x)/2; pq.push({dp[v][y-1], (ld)v, (ld)(y-1)}); } } } ld f = 1e18; for (int i=0; i<=K; ++i) { f = min(f, dp[H][i]); } return f; }
#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...