Submission #970915

#TimeUsernameProblemLanguageResultExecution timeMemory
970915mannshah1211Cyberland (APIO23_cyberland)C++17
0 / 100
3072 ms2097152 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; using state = tuple<long double, int, int>; const double eps = 1e-9; double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> a) { vector<vector<long double>> d(n, vector<long double>(k + 1, INT64_MAX)); 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] == 2) { if (d[to][used] - (expected + w) > -eps) { d[to][used] = expected + w; pq.push({d[to][used], to, used}); } } else if (a[to] == 1) { if (used < k - 1 && d[to][used + 1] - ((expected + (long double) w) / 2) > -eps) { d[to][used + 1] = (expected + (long double) w) / 2; pq.push({d[to][used + 1], to, used + 1}); } if (d[to][used] - (expected + w) > -eps) { d[to][used] = expected + w; pq.push({d[to][used], to, used}); } } else { if (d[to][used] > -eps) { d[to][used] = 0; pq.push({0, to, used}); } } } } long double cur = d[h][0]; for (int i = 0; i <= k; i++) { if (cur - d[h][i] > -eps) { cur = d[h][i]; } } 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...