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 fi first
#define se second
#define ll long long
using namespace std;
vector<pair<int, int>> adj[100042];
bool vis[100042];
double dist[100042][71];
double pows[128];
void initDfs(int node, int H) {
vis[node] = true;
for (auto& x: adj[node])
if (x.fi != H && !vis[x.fi])
initDfs(x.fi, H);
}
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, 70);
for (int i = 0; i < N; i++)
adj[i].clear();
pows[0] = 1;
for (int i = 1; i <= K + 1; i++)
pows[i] = pows[i - 1] / (double)2;
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]});
}
for (int i = 0; i < N; i++)
for (int j = 0; j <= K; j++)
dist[i][j] = 1e18;
for (int i = 0; i < N; i++)
vis[i] = false;
initDfs(0, H);
priority_queue<tuple<double, int, int>> nxt {};
arr[0] = 0;
/*for (int i = 0; i < N; i++) {
if (vis[i] && arr[i] == 0) {
dist[i][0] = 0;
nxt.push({0, 0, i});
}
}*/
nxt.push({0, 0, H});
dist[H][0] = 0;
while (!nxt.empty()) {
auto [dst, op2, at] = nxt.top();
nxt.pop();
dst *= -1;
if (arr[at] == 0)
return dst;
if (dist[at][op2] == dst) {
for (auto& x: adj[at]) {
// no divide
if (!vis[x.fi])
continue;
double nxtDst = dst + (double)x.se * pows[op2];
if (nxtDst < dist[x.fi][op2]) {
dist[x.fi][op2] = nxtDst;
nxt.push(make_tuple(-nxtDst, op2, x.fi));
}
// use divide
nxtDst = dst + (double)x.se * pows[op2 + 1];
if (arr[at] == 2 && op2 < K && nxtDst < dist[x.fi][op2 + 1]) {
dist[x.fi][op2 + 1] = nxtDst;
nxt.push(make_tuple(-nxtDst, op2 + 1, x.fi));
}
}
}
}
return -1;
}
# | 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... |