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>
using namespace std;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<pair<int, double>> adj[N];
for (int i = 0; i < M; i++) {
adj[x[i]].push_back({y[i], (double)c[i]});
adj[y[i]].push_back({x[i], (double)c[i]});
}
bool useful[N] = {};
queue<int> qu;
qu.push(0);
useful[0] = true;
while (qu.size()) {
int f = qu.front();
qu.pop();
if (f == H) continue;
for (auto [nf, _] : adj[f]) {
if (!useful[nf]) {
useful[nf] = true;
qu.push(nf);
}
}
}
vector<vector<double>> dst(min(K, 80)+1, vector<double>(N, 1e14));
double ans = 1e14;
for (int ii = 0; ii <= min(K, 80); ii++) {
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
for (int i = 0; i < N; i++) {
if (!useful[i]) continue;
if (arr[i] == 2 && ii) {
for (auto [j, v] : adj[i]) {
if (!useful[j] || j == H) continue;
dst[ii][i] = min(dst[ii][i], (dst[ii-1][j] + v) / 2.0);
}
pq.push({dst[ii][i], i});
} else if (!arr[i]) {
dst[ii][i] = 0;
pq.push({0, i});
}
}
if (!ii) {
dst[0][0] = 0;
pq.push({0, 0});
}
while (pq.size()) {
auto [d, f] = pq.top();
pq.pop();
if (d > dst[ii][f] || f == H) continue;
for (auto [nf, v] : adj[f]) {
if (d + v < dst[ii][nf] && useful[nf]) {
dst[ii][nf] = d + v;
pq.push({d+v, nf});
}
}
}
ans = min(ans, dst[ii][H]);
}
return ans;
}
# | 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... |