Submission #749258

#TimeUsernameProblemLanguageResultExecution timeMemory
749258SanguineChameleonCyberland (APIO23_cyberland)C++17
100 / 100
1401 ms102964 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; const int maxN = 1e5 + 20; const int maxK = 1e2 + 20; const double inf = 1e18; bool flag[maxN]; double dist[maxN][maxK]; vector<pair<int, int>> adj[maxN]; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { K = min(K, 67); for (int i = 0; i < N; i++) { flag[i] = false; for (int j = 0; j <= K; j++) { dist[i][j] = inf; } adj[i].clear(); } for (int i = 0; i < M; i++) { adj[x[i]].emplace_back(y[i], c[i]); adj[y[i]].emplace_back(x[i], c[i]); } flag[0] = true; deque<int> q; q.push_back(0); while (!q.empty()) { int u = q.front(); q.pop_front(); for (auto e: adj[u]) { int v = e.first; if (v != H && !flag[v]) { flag[v] = true; q.push_back(v); } } } for (int i = 0; i < N; i++) { if (flag[i] && (i == 0 || arr[i] == 0)) { dist[i][0] = 0.0; } } double res = inf; for (int k = 0; k <= K; k++) { priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q; for (int i = 0; i < N; i++) { if (i != H && dist[i][k] != inf) { q.emplace(dist[i][k], i); } } while (!q.empty()) { int u = q.top().second; double cur_d = q.top().first; q.pop(); if (cur_d != dist[u][k]) { continue; } for (auto e: adj[u]) { int v = e.first; int w = e.second; if (dist[u][k] + w < dist[v][k]) { dist[v][k] = dist[u][k] + w; if (v != H) { q.emplace(dist[v][k], v); } } if (arr[u] == 2) { dist[v][k + 1] = min(dist[v][k + 1], dist[u][k] / 2.0 + w); } } } res = min(res, dist[H][k]); } if (res == inf) { return -1; } else { return res; } }
#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...