# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
639806 | milisav | Valley (BOI19_valley) | C++14 | 300 ms | 88688 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 <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int M = 3e5+5;
int d[M], up[M][40], dp[M], mn[M][40], pr[M], ok[M], dist[M];
vector<array<int, 3>> node[M];
pair<int, int> v[M];
void dfs(int s, int p, int dd = 0, int D = 0) {
d[s] = D;
dist[s] = dd;
up[s][0] = p;
dp[s] = (!ok[s])*LLONG_MAX;
for (auto [i, w, x]:node[s]) {
if (i != p) {
if (v[x].first != s) swap(v[x].first, v[x].second);
dfs(i, s, dd+w, D+1);
dp[s] = min(dp[s], dp[i]+w*(dp[i]!=LLONG_MAX));
}
}
pr[s] = dp[s]-dd*(dp[s]!=LLONG_MAX);
}
int lca(int a, int b) {
if (d[a] < d[b]) swap(a, b);
for (int i = 0; i <= 20; i++) if ((d[a]-d[b])&(1<<i)) a = up[a][i];
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... |