#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
typedef long long ll;
const int N = 2001;
int A[N], B[N], W[N], n;
ll dp[N][N];
int k;
vector<pair<int, int>> g[N];
void dfs(int v, int p) {
vector<pair<int, int>> adj;
for (auto [to, w]: g[v]) {
if (to != p) {
dfs(to, v);
adj.emplace_back(to, w);
}
}
for (int con = max(0, min(k, (int) size(adj)) - 1); con <= min(k, (int) size(adj)); ++con) {
vector<ll> nw;
ll ans = 0;
for (auto [to, w]: adj) {
ans += dp[to][0] + w;
nw.push_back(dp[to][1] - dp[to][0] - w);
}
sort(all(nw));
for (int i = 0; i < con; ++i) {
if (nw[i] < 0)
ans += nw[i];
}
dp[v][min(k, (int) size(adj) + 1) - con] = ans;
}
for (int i = min((int) size(adj) + 1, k) - 1; i > -1; --i) {
dp[v][i] = min(dp[v][i], dp[v][i + 1]);
}
}
vector<ll> minimum_closure_costs(int nn, vector<int> uu, vector<int> vv, vector<int> ww) {
n = nn;
for (int i = 0; i < n - 1; ++i) {
A[i] = uu[i], B[i] = vv[i], W[i] = ww[i];
g[A[i]].emplace_back(B[i], W[i]);
g[B[i]].emplace_back(A[i], W[i]);
}
vector<ll> ans;
for (k = 0; k < n; ++k) {
dfs(0, -1);
ans.push_back(dp[0][0]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
418 ms |
8152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
27 ms |
5056 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
10328 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
10328 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
418 ms |
8152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |