QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560128#7684. Sweet SugarOkuchiriWA 121ms30552kbC++141.8kb2024-09-12 13:17:362024-09-12 13:17:36

Judging History

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

  • [2024-09-12 13:17:36]
  • 评测
  • 测评结果:WA
  • 用时:121ms
  • 内存:30552kb
  • [2024-09-12 13:17:36]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
#define mod 998244353
using namespace std;
vector<ll>e[1000010];
ll n,k,ans;
ll a[1000010],f[1000010][2];
void dfs(ll x,ll pre)
{
    f[x][0]=0;
    f[x][1]=0;
    ll s=0;
    ll b0=-4000000;
    for(auto y:e[x])
    {
        if(y==pre)continue;
        dfs(y,x);
        f[x][0]=max(f[x][0],f[y][0]);
        f[x][1]=max(f[x][1],f[y][1]);
        if(f[y][0]>f[y][1])
        {
            s+=f[y][0];
            if(f[y][1]!=f[y][0])b0=max(b0,f[y][1]-f[y][0]);//必须选一个数改变奇偶性
        }
        else
        {
            s+=f[y][1];
            if(f[y][1]!=f[y][0])b0=max(b0,f[y][0]-f[y][1]);//必须选一个数改变奇偶性
        }
    }
    if(a[x]%2==0)
    {
        if(s%2==0)
        {
            f[x][0]=max(f[x][0],s+a[x]);
            f[x][1]=max(f[x][1],s+b0+a[x]);
        }
        else
        {
            f[x][0]=max(f[x][0],s+a[x]+b0);
            f[x][1]=max(f[x][1],s+a[x]);
        }
    }
    else
    {
        if(s%2==0)
        {
            f[x][1]=max(f[x][1],s+a[x]);
            f[x][0]=max(f[x][1],s+a[x]+b0);
        }
        else
        {
            f[x][0]=max(f[x][0],s+a[x]+b0);
            f[x][1]=max(f[x][1],s+a[x]);
        }
    }
    //cout<<"x:"<<x<<' '<<f[x][0]<<' '<<f[x][1]<<'\n';
    if(f[x][k%2]>=k)
    {
        f[x][0]=0;
        f[x][1]=0;
        ans++;
    }
}
void work()
{
    ans=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i],e[i].clear();
    for(int i=1;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,0);
    cout<<ans<<'\n';
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)
    {
        work();
    }
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 30396kb

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

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: 121ms
memory: 30376kb

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