QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642453 | #7684. Sweet Sugar | ucup-team2526 | WA | 116ms | 11836kb | C++20 | 1.8kb | 2024-10-15 14:19:38 | 2024-10-15 14:19:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
std::cout << std::endl;
}
template<class T, class... Ts>
void err(T arg, Ts &... args) {
std::cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
const int maxn = 1e6 + 5;
vector<int>t[maxn];
int c[maxn],cnt0[maxn],cnt1[maxn],cnt2[maxn],dp[maxn];
int n,k;
void dfs(int u,int f) {
for (auto i : t[u]) {
if (i == f) continue;
dfs(i,u);
cnt0[u] += cnt0[i];
cnt1[u] += cnt1[i];
cnt2[u] += cnt2[i];
dp[u] += dp[i];
}
if ((k - c[u]) % 2 == 0) {
if (cnt2[u] * 2 + cnt1[u] >= (k - c[u])) {
dp[u]++;
cnt0[u] = cnt1[u] = cnt2[u] = 0;
}
else {
if (c[u] == 0) cnt0[u]++;
else if (c[u] == 1) cnt1[u]++;
else cnt2[u]++;
}
}
else {
if (cnt2[u] * 2 > (k - c[u])) {
if (cnt1[u]) {
dp[u]++;
cnt0[u] = cnt1[u] = cnt2[u] = 0;
}
else {
if (c[u] == 0) cnt0[u]++;
else if (c[u] == 1) cnt1[u]++;
else cnt2[u]++;
}
}
else {
if (cnt1[u] >= (k - c[u]) - cnt2[u] * 2) {
dp[u]++;
cnt0[u] = cnt1[u] = cnt2[u] = 0;
}
else {
if (c[u] == 0) cnt0[u]++;
else if (c[u] == 1) cnt1[u]++;
else cnt2[u]++;
}
}
}
}
void GENSHEN_START() {
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> c[i];
for (int i = 1;i <= n;i++) {
t[i].clear();
cnt0[i] = cnt1[i] = cnt2[i] = dp[i] = 0;
}
for (int i = 1;i < n;i++) {
int u,v;cin >> u >> v;
t[u].push_back(v);
t[v].push_back(u);
}
dfs(1,0);
cout << dp[1] << '\n';
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) GENSHEN_START();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11768kb
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: 3ms
memory: 11828kb
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: 116ms
memory: 11836kb
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 0 0 1 3 3 0 0 2 0 0 2 1 0 0 1 1 0 2 0 1 0 2 1 0 0 0 0 0 1 2 0 0 2 2 0 1 0 0 0 0 3 3 0 0 1 1 2 1 2 0 4 0 1 1 0 1 0 0 1 5 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 3 1 0 1 0 0 4 0 0 0 1 1 0 0 1 0 2 0 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 1 2 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 155th numbers differ - expected: '0', found: '1'