QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557331#7684. Sweet Sugarrotcar07WA 345ms30616kbC++14787b2024-09-11 09:00:282024-09-11 09:00:29

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 09:00:29]
  • 评测
  • 测评结果:WA
  • 用时:345ms
  • 内存:30616kb
  • [2024-09-11 09:00:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e6+5;
int n,k,a[maxn];
int ans,dp[maxn][2];
vector<int> e[maxn];
bool dfs(int p,int f){
    dp[p][0]=dp[p][1]=-1e9;
    dp[p][a[p]&1]=a[p];
    for(auto x:e[p])if(x!=f){
        if(dfs(x,p)) continue;
        int z[2]={-n,-n};
        for(int a:{0,1})for(int b:{0,1}) z[a^b]=max(z[a^b],dp[p][a]+dp[x][b]);
        dp[p][0]=z[0],dp[p][1]=z[1];
    }
    if(dp[p][k&1]>=k) return ++ans;
    else return 0;
}
inline void solve(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) e[i].clear();
    for(int i=1,u,v;i<n;i++) cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
    ans=0;dfs(1,0);
    cout<<ans<<'\n';
}
int main(){
    int t;cin>>t;
    while(t--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 29688kb

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: 30616kb

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: 345ms
memory: 30228kb

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
1
0
1
0
2
1
0
0
0
0
0
1
2
0
0
2
2
0
1
0
0
0
0
1
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
0
1
1
1
1
0
1
1
1
0
3
1
0
1
1
1
2
0
0
0
1
1
0
0
1
0
2
1
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
0
0
0
0
0
0
...

result:

wrong answer 20th numbers differ - expected: '2', found: '1'