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;
vector<pair<int, int>> g[100005];
bool reach[100005];
void dfsreach(int u, int H) {
if (reach[u])
return;
reach[u] = true;
if (u == H)
return;
for (auto v : g[u]) {
dfsreach(v.first, H);
}
}
long double dist[100005][32];
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y,
std::vector<int> c, std::vector<int> arr) {
for (int i = 0; i < M; i++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
dfsreach(0, H);
if (!reach[H]) {
for (int i = 0; i < N; i++) {
g[i].clear();
reach[i] = false;
}
return -1;
}
priority_queue<pair<long double, int>> pq;
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++)
dist[i][j] = 2e18;
if (arr[i] == 0 && reach[i]) {
pq.push({0, i});
dist[i][0] = 0;
}
}
pq.push({0, 0});
dist[0][0] = 0;
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
for (auto nxt : g[cur.second]) {
for (int j = 0; j < K; j++) {
if (arr[nxt.first] == 2) {
if (dist[nxt.first][j + 1] >
(-cur.first + nxt.second) * 0.5L) {
dist[nxt.first][j + 1] =
(-cur.first + nxt.second) * 0.5L;
pq.push({-dist[nxt.first][j + 1], nxt.first});
}
}
if (dist[nxt.first][j] > -cur.first + nxt.second) {
dist[nxt.first][j] = -cur.first + nxt.second;
pq.push({-dist[nxt.first][j], nxt.first});
}
}
}
}
for (int i = 0; i < N; i++) {
g[i].clear();
reach[i] = false;
}
long double mn = 2e18;
for (int j = 0; j < K; j++) {
mn = min(mn, dist[H][j]);
}
if (mn > 1e18)
return -1;
else
return mn;
}
# | 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... |