QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#393787#7684. Sweet SugarDeaphetSWA 143ms30332kbC++14811b2024-04-19 12:07:082024-04-19 12:07:08

Judging History

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

  • [2024-04-19 12:07:08]
  • 评测
  • 测评结果:WA
  • 用时:143ms
  • 内存:30332kb
  • [2024-04-19 12:07:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 1000010
int T,n,k,a[N],mx[N][2],ans;
vector<int>d[N];
const int Fk=-19990307;
void dfs(int x,int f)
{
	int t[2];
	mx[x][a[x]&1]=a[x];
	mx[x][(a[x]&1)^1]=Fk;
	for(auto y:d[x])if(y!=f){
		dfs(y,x);
		t[0]=0,t[1]=Fk;
		for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			t[i^j]=max(t[i^j],mx[x][i]+mx[y][j]);
		for(int i=0;i<2;i++)mx[x][i]=t[i];
	}
	if(mx[x][k&1]>=k)ans++,mx[x][0]=0,mx[x][1]=Fk;
	mx[x][0]=max(mx[x][0],0);
}
void init()
{
	ans=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		d[i].clear();
	}
	for(int i=2;i<=n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		d[u].push_back(v);
		d[v].push_back(u);
	}
	dfs(1,0);
	printf("%d\n",ans);
}
int main()
{
	scanf("%d",&T);
	while(T--)init();
}

詳細信息

Test #1:

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

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

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: 143ms
memory: 30276kb

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