Submission #970933

#TimeUsernameProblemLanguageResultExecution timeMemory
970933mannshah1211Cyberland (APIO23_cyberland)C++17
97 / 100
3014 ms94116 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; using state = tuple<double, int, int>; const double eps = 1e-9; const double inf = 1e14; double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> a) { k = min(k, 69); vector<vector<double>> d(n, vector<double>(k + 1, inf)); vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; i++) { g[x[i]].push_back(make_pair(y[i], c[i])); g[y[i]].push_back(make_pair(x[i], c[i])); } d[0][0] = 0; priority_queue<state, vector<state>, greater<state>> pq; pq.push({0, 0, 0}); while (!pq.empty()) { auto [expected, who, used] = pq.top(); pq.pop(); if (d[who][used] - expected < -eps) { continue; } if (who == h) { continue; } for (auto [to, w] : g[who]) { if (a[to] == 1) { if (d[to][used] > expected + w) { d[to][used] = expected + w; pq.push({d[to][used], to, used}); } } else if (a[to] == 2) { if (used <= k - 1 && d[to][used + 1] > ((expected + (double) w) / 2)) { d[to][used + 1] = (expected + (double) w) / 2; pq.push({d[to][used + 1], to, used + 1}); } if (d[to][used] > expected + w) { d[to][used] = expected + w; pq.push({d[to][used], to, used}); } } else { if (d[to][used] > 0) { d[to][used] = 0; pq.push({0, to, used}); } } } } double cur = d[h][0]; for (int i = 0; i <= k; i++) { if (cur > d[h][i]) { cur = d[h][i]; } } if (abs(cur - inf) < eps) { return -1; } return cur; }
#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...