QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642734 | #7684. Sweet Sugar | ucup-team2526 | WA | 117ms | 5752kb | C++20 | 1.4kb | 2024-10-15 16:02:45 | 2024-10-15 16:02:46 |
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 dp[maxn][2],c[maxn],ans;
int n,k;
void dfs(int u,int f) {
if (c[u] == 1) dp[u][1] = 1,dp[u][0] = -1;
else if (c[u] == 2) dp[u][1] = -1,dp[u][0] = 2;
for (auto i : t[u]) {
if (i == f) continue;
dfs(i,u);
int tmp0 = dp[u][0],tmp1 = dp[u][1];
if (dp[i][1] != -1 && tmp0 != -1) dp[u][1] = dp[i][1] + tmp0;
if (tmp1 != -1 && dp[i][0] != -1) dp[u][1] = max(dp[u][1],dp[i][0] + tmp1);
if (dp[i][0] != -1 && tmp0 != -1) dp[u][0] = dp[i][0] + tmp0;
if (dp[i][1] != -1 && tmp1 != -1) dp[u][0] = max(dp[u][0],dp[i][1] + tmp1);
}
if (dp[u][k&1] >= k) {
ans++;
dp[u][1] = dp[u][0] = -1;
}
}
void GENSHEN_START() {
ans = 0;
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> c[i];
for (int i = 1;i <= n;i++) {
t[i].clear();
dp[i][0] = dp[i][1] = -1;
}
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 << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) GENSHEN_START();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5752kb
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: 2ms
memory: 5740kb
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: 117ms
memory: 5712kb
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 0 3 3 0 0 2 0 0 2 1 0 0 1 1 0 2 0 1 0 2 0 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 0 1 0 1 0 0 1 5 0 1 1 1 0 1 1 1 1 1 1 0 0 0 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 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 1 1 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 5th numbers differ - expected: '1', found: '0'