QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#684492 | #6107. One Path | hhoppitree | WA | 0ms | 6200kb | C++17 | 1.2kb | 2024-10-28 13:54:30 | 2024-10-28 13:54:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int m;
long long f[N][N][3];
vector< pair<int, int> > G[N];
int dfs(int x, int fa = -1, long long lst = -1e18) {
int sz = 0;
for (auto [v, w] : G[x]) {
if (v == fa) continue;
int tsz = dfs(v, x, w);
sz += tsz;
for (int i = 2; ~i; --i) {
for (int j = 2 - i; ~j; --j) {
for (int p = min(m, sz); ~p; --p) {
for (int q = min(m - p, tsz); ~q; --q) {
f[x][p + q][i + j] = max(f[x][p + q][i + j], f[x][p][i] + f[v][q][j] + (j == 1 ? w : 0));
}
}
}
}
}
for (int i = 0; i < m; ++i) {
f[x][i + 1][0] = max(f[x][i + 1][0], f[x][i][2] + lst);
}
return sz + 1;
}
signed main() {
int n; scanf("%d%d", &n, &m);
for (int i = 1, x, y, v; i < n; ++i) {
scanf("%d%d%d", &x, &y, &v);
G[x].push_back({y, v});
G[y].push_back({x, v});
}
dfs(1);
for (int i = 0; i <= m; ++i) {
printf("%lld%c", *max_element(f[1][i], f[1][i] + 3), " \n"[i == m]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3916kb
input:
5 1 1 3 2 4 5 4 3 4 3 2 3 7
output:
14 16
result:
ok 2 number(s): "14 16"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
7 2 1 2 4 2 3 6 2 4 2 4 5 5 2 6 1 4 7 3
output:
13 20 21
result:
ok 3 number(s): "13 20 21"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 6200kb
input:
50 2000 3 34 1 37 39 58720256 17 24 14680064 28 39 1 25 38 1 21 29 1 3 30 1 26 36 1 5 48 14336 4 22 1 26 41 1 41 44 1 5 14 1 23 25 28672 40 41 224 27 39 1 4 20 7340032 7 47 939524096 11 46 114688 30 49 3584 34 44 1 7 35 1 10 29 1 27 33 29360128 16 36 56 8 28 1 13 38 57344 34 45 896 15 35 469762048 1...
output:
1409286145 1761607683 1849688069 1871708167 1877213193 1878589451 1878933517 1879019535 1879041041 1879046419 1879047765 1879048103 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 187...
result:
wrong answer 100th numbers differ - expected: '1879048160', found: '0'