QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658971#7684. Sweet SugarNightskyWA 144ms32828kbC++141.1kb2024-10-19 18:05:022024-10-19 18:05:02

Judging History

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

  • [2024-10-19 18:05:02]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:32828kb
  • [2024-10-19 18:05:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+5;
int C[MAXN],siz[MAXN],n,k,ans,mi[MAXN];
vector <int> e[MAXN];
bool cut[MAXN];
void dfs(int p,int fa)
{
    siz[p]=C[p];mi[p]=2*n;
    for(int v:e[p])
    {
        if(v!=fa)
        {
            dfs(v,p);
            if(!cut[v])
            {
                siz[p]+=siz[v];
                if(C[v]==1) mi[p]=min(mi[p],mi[v]);
            }
        }
    }
    if(C[p]==1) mi[p]=min(mi[p],siz[p]);
    if((siz[p]>=k&&((siz[p]%2==k%2)||(siz[p]%2!=k%2&&siz[p]-k>=mi[p])))||siz[p]==k)
    {
        ++ans;
        cut[p]=1;
    }
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d %d",&n,&k);ans=0;
        for(int i=1;i<=n;++i) e[i].clear(),cut[i]=0;
        for(int i=1;i<=n;++i) scanf("%d",&C[i]);
        for(int i=1;i<n;++i)
        {
            int u,v;
            scanf("%d %d",&u,&v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
        dfs(1,0);
        printf("%d\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 32828kb

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

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: 144ms
memory: 32576kb

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
0
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 69th numbers differ - expected: '1', found: '0'