# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
744535 | RushB | Road Closures (APIO21_roads) | C++17 | 275 ms | 5204 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 "roads.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 2;
long long dp[N][2];
int X;
vector<array<int, 2>> adj[N];
void dfs(int v, int p) {
long long dif = 0, ans = 0, mx = 0;
vector<long long> V;
V.reserve(adj[v].size());
for (auto P: adj[v]) {
int u = P[0], w = P[1];
if (u == p) continue;
dfs(u, v);
dif += dp[u][0];
V.push_back(w + dp[u][1] - dp[u][0]);
}
sort(V.rbegin(), V.rend());
for (int i = 0; i <= X && i <= V.size(); i++) {
if (i) ans += V[i - 1];
mx = max(mx, ans);
if (i + 1 == X) dp[v][1] = mx + dif;
}
if (V.size() + 1 < X) dp[v][1] = mx + dif;
dp[v][0] = mx + dif;
}
vector<long long> minimum_closure_costs(int n, vector<int> U, vector<int> V, vector<int> W) {
assert(n < N);
long long all = 0;
for (int i = 0; i < U.size(); i++) {
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
all += W[i];
}
vector<long long> re(n);
re[0] = all;
for (int i = 1; i < n; i++) X = i, dfs(0, 0), re[i] = all - dp[0][0];
return re;
}
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... |