# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978149 | math_rabbit_1028 | Cyberland (APIO23_cyberland) | C++17 | 3040 ms | 29756 KiB |
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;
typedef long long ll;
typedef pair<ll, ll> pll;
int n, m, k, h;
vector<pll> adj[101010];
int ch[101010];
void DFS(int v) {
if (v == h) return;
if (ch[v]) return;
ch[v] = 1;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i].first;
DFS(u);
}
}
double dis[31][101010];
priority_queue< pair<double, ll> > pq;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
n = N; m = M; k = K; h = H;
for (int i = 0; i < n; i++) adj[i].clear();
for (int i = 0; i < m; i++) {
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
for (int i = 0; i < n; i++) ch[i] = 0;
DFS(0);
dis[k][0] = 0;
pq.push({-dis[k][0], k*n+0});
for (int i = 1; i < n; i++) {
if (arr[i] == 0 && ch[i] == 1) {
dis[k][i] = 0;
pq.push({-dis[k][i], k*n+i});
}
else {
dis[k][i] = 1e18;
}
}
for (int t = 0; t < k; t++) {
for (int i = 0; i < n; i++) dis[t][i] = 1e18;
}
while (!pq.empty()) {
int v = pq.top().second % n, t = pq.top().second / n; double w = -pq.top().first;
pq.pop();
if (dis[t][v] < w) continue;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i].first; ll ww = adj[v][i].second;
if (dis[t][u] > w + ww) {
dis[t][u] = w + ww;
pq.push({-dis[t][u], t*n+u});
}
if (arr[u] != 2) continue;
if (t == 0) continue;
if (dis[t-1][u] > (w + ww) / 2.0) {
dis[t-1][u] = (w + ww) / 2.0;
pq.push({-dis[t-1][u], (t-1)*n+u});
}
}
}
double ans = 1e18;
for (int t = 0; t <= k; t++) {
ans = min(ans, dis[t][h]);
}
if (ans >= 1e17) return -1;
else return ans;
}
Compilation message (stderr)
# | 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... |