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;
const double INFF = 1e18;
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<vector<pair<int, double>>> v(n);
for (int i = 0; i < m; i++) {
v[x[i]].push_back({y[i], c[i]});
v[y[i]].push_back({x[i], c[i]});
}
k = min(k, 70);
vector<vector<double>> dist(n, vector<double>(k + 1, INFF));
priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<tuple<double, int, int>>> pq;
dist[0][0] = 0;
pq.push({0, 0, 0});
for (int _ = 0; _ <= k; _++) {
priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<tuple<double, int, int>>> tmp;
while (!pq.empty()) {
auto [d, x, ck] = pq.top();
pq.pop();
if (dist[x][ck] < d || x == h) continue;
for (auto [z, c] : v[x]) {
if (arr[z] == 0 && 0 < dist[z][ck]) {
dist[z][ck] = 0;
pq.push({dist[z][ck], z, ck});
}
if (arr[z] == 1 && d + c < dist[z][ck]) {
dist[z][ck] = d + c;
pq.push({dist[z][ck], z, ck});
}
if (arr[z] == 2 && d + c < dist[z][ck]) {
dist[z][ck] = d + c;
pq.push({dist[z][ck], z, ck});
}
if (ck < k && arr[z] == 2 && (d + c) / (double) (2) < dist[z][ck + 1]) {
dist[z][ck + 1] = (d + c) / (double) (2);
tmp.push({dist[z][ck + 1], z, ck + 1});
}
}
}
swap(pq, tmp);
}
double ans = INFF;
for (int ck = 0; ck <= k; ck++) ans = min(ans, dist[h][ck]);
// loh bisa -1
return (ans == INFF ? -1 : 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... |