QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739429#7684. Sweet Sugarrqoi031WA 136ms5720kbC++201.3kb2024-11-12 21:45:012024-11-12 21:45:06

Judging History

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

  • [2024-11-12 21:45:06]
  • 评测
  • 测评结果:WA
  • 用时:136ms
  • 内存:5720kb
  • [2024-11-12 21:45:01]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<tuple>
struct edge {
    int v,next;
};
edge e[2000005];
int en,last[1000005];
inline void add_edge(const int &u,const int &v) {
    e[++en]={v,last[u]},last[u]=en;
    e[++en]={u,last[v]},last[v]=en;
}
int c[1000005];
inline void solve() {
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) {
        scanf("%d",c+i);
    }
    std::fill(last+1,last+n+1,0),en=0;
    for(int i=1;i<n;i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
    }
    const auto dfs([&](const auto &self,const int &u,const int &fa)->std::tuple<int,int,int> {
        int s(0),x(c[u]==2?2:0),y(c[u]==1?1:-1000000001);
        for(int i=last[u];i;i=e[i].next) {
            const int &v(e[i].v);
            if(v==fa) {
                continue;
            }
            const auto &[s0,x0,y0](self(self,v,u));
            s+=s0;
            x=std::max({x,x0,x+x0,y+y0});
            y=std::max({y,y0,x+y0,y+x0});
        }
        if((k&1?y:x)>=k) {
            ++s,x=-1000000000,y=-1000000001;
        }
        return {s,x,y};
    });
    printf("%d\n",std::get<0>(dfs(dfs,1,0)));
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

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: 1ms
memory: 5720kb

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: 136ms
memory: 5708kb

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

result:

wrong answer 3rd numbers differ - expected: '0', found: '1'