QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#262653 | #7684. Sweet Sugar | Ashoka | WA | 150ms | 3612kb | C++20 | 1.1kb | 2023-11-23 21:15:35 | 2023-11-23 21:15:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr i64 inf = 1E18;
void solve() {
int n, k;
cin >> n >> k;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
vector<vector<int>> adj(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
--u; --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector dp(n, array<i64, 2> ({0, -inf}));
int ans = 0;
auto dfs = [&](auto self, int u, int fa) -> void {
dp[u][c[u] & 1] = c[u];
for (auto v : adj[u]) {
if (v == fa) continue;
self(self, v, u);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
dp[u][i ^ j] = max(dp[u][i ^ j], dp[v][i] + dp[u][j]);
}
}
}
if (dp[u][k & 1] >= k) {
ans += 1;
dp[u] = {0, -inf};
}
dp[u][0] = max(dp[u][0], 0LL);
return ;
};
dfs(dfs, 0, -1);
cout << ans << "\n";
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
4 7 5 1 2 1 2 2 1 2 1 2 2 3 3 4 3 5 5 6 5 7 2 2 1 0 1 2 1 1 1 1 2 1
output:
2 0 1 0
result:
ok 4 number(s): "2 0 1 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
12 1 1 0 1 1 1 1 1 2 1 2 0 1 2 1 1 2 2 1 3 0 1 3 1 1 3 2 1 2000000 0 1 2000000 1 1 2000000 2
output:
0 1 0 0 0 1 0 0 0 0 0 0
result:
ok 12 numbers
Test #3:
score: -100
Wrong Answer
time: 150ms
memory: 3444kb
input:
200000 5 2 1 1 0 0 1 2 4 5 2 4 1 3 2 5 1 0 0 0 0 0 5 1 1 2 3 2 5 4 5 3 1 0 0 0 1 1 4 4 2 3 4 5 2 5 9 1 0 0 0 2 4 3 2 1 3 1 5 1 5 3 0 1 1 0 1 5 4 2 1 4 3 5 1 5 1 0 2 1 1 1 5 3 2 4 3 4 1 4 5 1 1 0 1 1 0 1 5 4 2 1 3 5 2 5 7 0 2 1 1 2 5 1 2 3 2 5 5 4 5 5 0 1 0 1 0 2 4 4 3 5 2 1 5 5 1 0 0 1 0 1 4 1 4 5 2...
output:
1 0 1 0 1 3 3 1 1 2 0 0 2 1 1 1 1 1 1 2 0 1 0 2 1 1 1 0 0 1 1 2 1 0 2 2 0 1 0 0 0 1 3 3 1 1 1 1 3 1 2 0 4 1 1 1 0 1 1 0 1 5 0 1 1 1 1 1 1 1 1 1 2 0 1 1 1 0 3 1 0 1 0 0 4 0 1 0 1 1 0 0 1 0 2 0 5 1 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 2 0 1 2 0 0 2 0 1 1 0 0 0 0 1 ...
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'