QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547643 | #7684. Sweet Sugar | rookiefyq | WA | 135ms | 30336kb | C++14 | 1.0kb | 2024-09-05 00:40:12 | 2024-09-05 00:40:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+999;
int c[N], n, k;
vector<int> e[N];
int dp[N][2], ans;
void dfs(int u, int fa){
if(c[u] == 1)
dp[u][1] = 1, dp[u][0] = 0;
else if(c[u] == 2)
dp[u][1] = -1e7, dp[u][0] = 2;
else dp[u][0] = 0, dp[u][1] = -1e7;
for(auto v : e[u]){
if(v == fa) continue;
dfs(v, u);
int t0, t1;
t0 = max(dp[u][0] + dp[v][0], dp[u][1] + dp[v][1]);
t1 = max(dp[u][1] + dp[v][0], dp[u][0] + dp[v][1]);
dp[u][0] = t0, dp[u][1] = t1;
}
if(dp[u][k & 1] >= k){
ans++;
dp[u][0] = 0;
dp[u][1] = -1e7;
}
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> c[i];
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
ans = 0;
dfs(1, 0);
cout << ans << '\n';
for(int i = 1; i <= n; i++)
e[i].clear();
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 28148kb
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: 28212kb
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: 135ms
memory: 30336kb
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 2 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 73rd numbers differ - expected: '1', found: '2'