QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#646338 | #8938. Crawling on a Tree | ucup-team173 | WA | 0ms | 3832kb | C++20 | 2.0kb | 2024-10-16 22:18:27 | 2024-10-16 22:18:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int ll
using ll = long long;
constexpr int inf = 1e18;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector G(n + 1, vector<array<int, 3>>());
for(int i = 1; i < n; i++) {
int u, v, l, k;
cin >> u >> v >> l >> k;
G[u].push_back({v, l, k});
G[v].push_back({u, l, k});
}
vector<int> c(n + 1), ek(n + 1), el(n + 1), fa(n + 1);
for(int i = 2; i <= n; i++) {
cin >> c[i];
}
vector f(n + 1, vector(m + 1, 0ll));
auto merge = [&](vector<int> f, vector<int> g, int l, int r) -> vector<int> {
vector<int> res(m + 1, inf);
int i = 0, j = l;
while(i < m && f[i] == inf) i++;
while(j < r && g[j] == inf) j++;
while(i + j <= m) {
res[i + j] = f[i] + g[j];
if(j < r && f[i] + g[j + 1] < f[i + 1] + g[j]) j++;
else i++;
}
return res;
};
auto dfs = [&](auto self, int x, int fz) -> void {
fa[x] = fz;
for(auto [y, l, k] : G[x]) if(y != fz) {
ek[y] = k, el[y] = l;
self(self, y, x);
c[x] = max(c[x], c[y]);
for(int i = 0; i <= m; i++) {
f[y][i] += (2 * max(c[y], i) - i) * el[y];
}
if(ek[y] < c[y]) {
f[x] = vector(m + 1, inf);
} else {
f[x] = merge(f[x], f[y], max(2 * c[y] - ek[y], 0ll), min(m, ek[y]));
}
}
};
dfs(dfs, 1, 0);
// for(int i = 1; i <= n; i++) {
// cerr << i << ": ";
// for(int j = 0; j <= m; j++) {
// cerr << f[i][j] << " \n"[j == m];
// }
// }
vector<int> ans(m + 1, inf);
for(int i = 0; i <= m; i++) {
ans[max(c[1], i)] = min(ans[max(c[1], i)], f[1][i]);
}
for(int i = 1; i <= m; i++) {
if(ans[i] == inf) ans[i] = -1;
cout << ans[i] << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
input:
4 2 1 2 3 2 2 3 2 1 2 4 5 1 1 1 1
output:
-1 13
result:
ok 2 number(s): "-1 13"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
4 2 1 2 3 2 2 3 2 1 2 4 5 1 2 2 2
output:
-1 -1
result:
ok 2 number(s): "-1 -1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 1 2 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 50 2 1 1 1 50
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 50 2 1 1 50 50
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 50
result:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 50 1 2 1 100000 50
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 50
result:
ok 50 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
50 1 1 2 85524 58896 2 3 9137 9819 3 4 3036 88987 4 5 78909 15766 5 6 76067 34996 6 7 64247 63701 7 8 14 9384 8 9 37698 35418 9 10 51427 91691 10 11 39818 89351 11 12 47887 64083 12 13 43836 44135 13 14 22561 83803 14 15 52617 97413 15 16 41869 83810 16 17 35783 18642 17 18 5514 34601 18 19 50448 49...
output:
3202064
result:
ok 1 number(s): "3202064"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
50 5 1 2 48897 1 2 3 59967 3 3 4 61806 2 4 5 48519 4 5 6 77213 5 6 7 32384 1 7 8 59009 2 8 9 98263 1 9 10 42945 6 10 11 5549 6 11 12 51097 6 12 13 88536 4 13 14 44215 2 14 15 56896 2 15 16 19263 5 16 17 30787 5 17 18 20135 3 18 19 75922 4 19 20 35387 5 20 21 84081 4 21 22 54235 5 22 23 44411 3 23 24...
output:
-1 -1 -1 -1 -1
result:
ok 5 number(s): "-1 -1 -1 -1 -1"
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3564kb
input:
50 10 1 2 44914 14 2 3 84737 11 3 4 76461 7 4 5 36207 14 5 6 48479 10 6 7 88167 14 7 8 71415 7 8 9 95290 10 9 10 12553 7 10 11 2718 7 11 12 89004 12 12 13 86605 10 13 14 76252 14 14 15 75076 10 15 16 52024 14 16 17 23365 15 17 18 93829 13 18 19 3765 10 19 20 72010 9 20 21 17119 7 21 22 83633 14 22 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 3rd numbers differ - expected: '9947212', found: '-1'