QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672976#7684. Sweet Sugari0streamWA 43ms11988kbC++141.1kb2024-10-24 20:06:462024-10-24 20:06:46

Judging History

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

  • [2024-10-24 20:06:46]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:11988kb
  • [2024-10-24 20:06:46]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int N=1e6+100;

int dp[N][2],a[N],n,T,k,u,v,ans;
int E,head[N],to[N<<1],nxt[N<<1];

int read(){
    int flag=1,x=0,c=getchar();
    while (c<'0' || c>'9'){if (c=='-') flag=-1;c=getchar();}
    while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*flag;
}

void addedge(int u,int v){
    to[++E]=v;
    nxt[E]=head[u];
    head[u]=E;
}

void dfs(int u,int F){
	int t=a[u]&1;
	dp[u][t]=a[u];dp[u][t^1]=0;
	for (int e=head[u];e;e=nxt[e]){
		int v=to[e];
		if (v==F) continue;
		dfs(v,u);
		int u0=max(dp[u][0]+dp[v][0],dp[u][1]+dp[v][1]);
		int u1=max(dp[u][1]+dp[v][0],dp[u][0]+dp[v][1]);
		dp[u][0]=u0;dp[u][1]=u1;
	}
	//cout<<u<<' '<<dp[u][0]<<" "<<dp[u][1]<<endl;
	if (dp[u][k&1]>=k){
		ans++;
		dp[u][0]=0;
		dp[u][1]=0;
	}
}

int main(){
	T=read();
	while (T--){
		n=read();k=read();
		E=0;ans=0;
		for (int i=1;i<=n;i++) head[i]=0,dp[i][0]=0,dp[i][1]=0;
		for (int i=1;i<=n;i++) a[i]=read();
		for (int i=1;i<n;i++){
			u=read();v=read();
			addedge(u,v);addedge(v,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: 2ms
memory: 11988kb

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

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: 43ms
memory: 11940kb

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

result:

wrong answer 24th numbers differ - expected: '2', found: '3'