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 INF = 1e15;
double solve(int N, int M, int K, int H, vector<int> x,
vector<int> y, vector<int> c, vector<int> arr) {
vector adj(N, vector<pair<int, int>>());
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]);
}
vector<int> mark(N, 0);
const auto connected = [&](const auto &self, int u, int target) -> bool {
mark[u] = 1;
for(auto [v, c] : adj[u]) if(!mark[v]) {
if(self(self, v, target)) return true;
}
return false;
};
if(!connected(connected, 0, H)) {
return -1.0;
}
const auto dijkstra = [&](const vector<int> &sources, vector<double> &dist) {
using state = pair<double, int>; // dist, node
vector<int> vis(N, 0);
priority_queue<state, vector<state>, greater<state>> pq;
for(int i : sources) pq.push({dist[i], i});
while(!pq.empty()) {
int u = pq.top().second; pq.pop();
if(vis[u]) continue;
vis[u] = 1;
for(auto [v, c] : adj[u]) {
if(dist[v] > dist[u] + c) {
pq.push({dist[v] = dist[u] + c, v});
}
}
}
};
vector<int> sources{0};
for(int i = 1; i < N; i++) if(arr[i] == 0)
sources.push_back(i);
vector<double> dist(N, INF);
for(int i : sources)
dist[i] = 0.0;
double ans = INF;
for(int it = 0; it < min(K, 95); it++) {
if(it == 1) {
sources.clear();
for(int i = 0; i < N; i++) if(arr[i] != 1)
sources.push_back(i);
}
if(it > 0) {
for(int i = 0; i < N; i++) {
if(arr[i] == 0) dist[i] = 0.0;
else if(arr[i] == 1) dist[i] = INF;
else dist[i] /= 2.0;
}
}
dijkstra(sources, dist);
ans = min(ans, dist[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... |