This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include <bits/stdc++.h>
#define pii pair<ll, ll>
typedef long long ll;
using namespace std;
const int MAX = 100007;
vector<pii> G[MAX];
bool V[MAX];
ll D[MAX], LD[MAX];
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) {
for (int i = 0; i < M; ++i) {
G[x[i]].emplace_back(y[i], c[i]);
G[y[i]].emplace_back(x[i], c[i]);
}
V[0] = 1;
queue<int> Q;
Q.push(0);
while (!Q.empty()) {
int cur = Q.front(); Q.pop();
for (auto [next, _] : G[cur]) {
if (V[next]) continue;
V[next] = 1;
Q.push(next);
}
}
if (!V[H]) return -1;
memset(D, 0x3f, sizeof(D));
priority_queue<pii, vector<pii>, greater<pii>> PQ;
for (int i = 0; i < N; ++i) {
if (i && arr[i]) continue;
PQ.emplace(D[i] = 0, i);
}
while (!PQ.empty()) {
auto [cd, cur] = PQ.top(); PQ.pop();
if (cd > D[cur]) continue;
for (auto [next, nd] : G[cur]) {
if (D[next] <= cd + nd) continue;
PQ.emplace(D[next] = cd + nd, next);
}
}
memset(LD, 0x3f, sizeof(LD));
PQ.emplace(LD[H] = 0, H);
while (!PQ.empty()) {
auto [cd, cur] = PQ.top(); PQ.pop();
if (cd > LD[cur]) continue;
for (auto [next, nd] : G[cur]) {
if (LD[next] <= cd + nd) continue;
PQ.emplace(LD[next] = cd + nd, next);
}
}
double ans = D[H];
if (K) {
for (int i = 0; i < N; ++i) {
if (arr[i] != 2 || !V[i]) continue;
ll a = D[i], b = LD[i], c = 1e18;
for (auto [next, nd] : G[i]) c = min(c, nd);
double cd = (double)a / 2.0;
for (int k = 1; k < min(100, K); ++k) {
cd = (cd + 2LL * c) / 2.0;
}
ans = min(ans, cd);
}
}
return ans;
}
Compilation message (stderr)
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:63:17: warning: unused variable 'b' [-Wunused-variable]
63 | ll a = D[i], b = LD[i], c = 1e18;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |