0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:08:47 +00:00

4033. [HAOI2015]树上染色

https://hydro.ac/d/bzoj/record/6322ed5cbdf9bc31d160a143
This commit is contained in:
Baoshuo Ren 2022-09-15 17:16:44 +08:00
parent 686aaa9256
commit 1d2f77ea7d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 125 additions and 0 deletions

65
BZOJ/4033/4033.cpp Normal file
View File

@ -0,0 +1,65 @@
#include <iostream>
#include <cstring>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005;
int n, k, fa[N], siz[N];
long long f[N][N];
std::vector<std::pair<int, int>> g[N];
void dfs(int u, int fa) {
siz[u] = 1;
f[u][0] = f[u][1] = 0;
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (v == fa) continue;
dfs(v, u);
siz[u] += siz[v];
for (int i = std::min(k, siz[u]); ~i; i--) {
if (~f[u][i]) {
f[u][i] += f[v][0] + 1ll * siz[v] * (n - k - siz[v]) * w;
}
for (int j = std::min(i, siz[v]); j; j--) {
if (~f[u][i - j]) {
f[u][i] = std::max(f[u][i], f[u][i - j] + f[v][j] + 1ll * (j * (k - j) + (siz[v] - j) * (n - k - siz[v] + j)) * w);
}
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
k = std::max(k, n - k);
for (int i = 1, u, v, w; i < n; i++) {
cin >> u >> v >> w;
g[u].push_back(std::make_pair(v, w));
g[v].push_back(std::make_pair(u, w));
}
memset(f, 0xff, sizeof(f));
dfs(1, 0);
cout << f[1][k] << endl;
return 0;
}

BIN
BZOJ/4033/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4033/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.