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 <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
const int maxN = 1e5 + 20;
const int maxK = 1e2 + 20;
const double inf = 1e18;
bool flag[maxN];
double dist[maxN][maxK];
vector<pair<int, int>> adj[maxN];
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, 100);
for (int i = 0; i < N; i++) {
flag[i] = false;
for (int j = 0; j <= K; j++) {
dist[i][j] = inf;
}
}
for (int i = 0; i < M; i++) {
adj[x[i]].emplace_back(y[i], c[i]);
adj[y[i]].emplace_back(x[i], c[i]);
}
flag[0] = true;
deque<int> q;
q.push_back(0);
while (!q.empty()) {
int u = q.front();
q.pop_front();
for (auto e: adj[u]) {
int v = e.first;
if (v != H && !flag[v]) {
flag[v] = true;
q.push_back(v);
}
}
}
for (int i = 0; i < N; i++) {
if (flag[i] && (i == 0 || arr[i] == 0)) {
dist[i][0] = 0.0;
}
}
double res = inf;
for (int k = 0; k <= K; k++) {
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
for (int i = 0; i < N; i++) {
if (i != H && dist[i][k] != inf) {
q.emplace(dist[i][k], i);
}
}
while (!q.empty()) {
int u = q.top().second;
double cur_d = q.top().first;
q.pop();
if (cur_d != dist[u][k]) {
continue;
}
for (auto e: adj[u]) {
int v = e.first;
int w = e.second;
if (dist[u][k] + w < dist[v][k]) {
dist[v][k] = dist[u][k] + w;
if (v != H) {
q.emplace(dist[v][k], v);
}
}
if (arr[u] == 2) {
dist[v][k + 1] = min(dist[v][k + 1], dist[u][k] / 2.0 + w);
}
}
}
res = min(res, dist[H][k]);
}
if (res == inf) {
return -1;
}
else {
return res;
}
}
# | 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... |