QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863574#7684. Sweet Sugarjuan_123WA 116ms31132kbC++141.1kb2025-01-19 19:26:472025-01-19 19:26:58

Judging History

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

  • [2025-01-19 19:26:58]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:31132kb
  • [2025-01-19 19:26:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1000000000;
int n,k,ans = 0;
vector<int>p[1000005];
int mx[1000005][2],a[1000005];
void dfs(int now,int fa){
	mx[now][a[now]&1] = a[now];
	mx[now][(a[now]&1)^1] = -inf;
//	cout << " " << mx[now][0] << " " << mx[now][1] << endl;
	for(auto x:p[now]){
		if(x == fa)continue;
		dfs(x,now);
		int f0 = -inf,f1 = -inf;
		f0 = max(mx[now][0]+mx[x][0],mx[now][1]+mx[x][1]);
		f1 = max(mx[now][0]+mx[x][1],mx[now][1]+mx[x][0]);
		mx[now][0] = f0,mx[now][1] = f1;
	}
//	cout << now << " " << mx[now][0] << " " << mx[now][1] << endl;
	if(mx[now][k&1]>=k){
		++ans;
		mx[now][0] = 0;
		mx[now][1] = -inf;
	}
	
}
void solve(){
	ans = 0;
	for(int i =1;i<=n;i++)p[i].clear();
	cin >> n >> k;
	for(int i = 1;i<=n;i++)cin >> a[i];
	for(int i = 1;i<n;i++){
		int a,b;cin >>a >> b;
		p[a].push_back(b),p[b].push_back(a);
	}
	dfs(1,1);
	cout << ans << '\n';
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin >> t;
	while(t--)solve();
	return 0;
}/*
1
7 5
1 2 1 2 2 1 2
1 2
2 3
3 4
3 5
5 6
5 7
*/

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 29464kb

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

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: 116ms
memory: 31036kb

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

result:

wrong answer 20th numbers differ - expected: '2', found: '1'