QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#611112#7684. Sweet SugarANIG#WA 162ms3616kbC++141.1kb2024-10-04 19:25:582024-10-04 19:25:58

Judging History

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

  • [2024-10-04 19:25:58]
  • 评测
  • 测评结果:WA
  • 用时:162ms
  • 内存:3616kb
  • [2024-10-04 19:25:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;

int n,ans,k;
vector<vector<int>> ver;
vector<int> a;

pair<int,int> dfs(int u,int fa=0){
	int s=0,x=(a[u]!=1?-inf:a[u]),y=(a[u]!=1?a[u]:-inf);
	vector<pair<int,int>> tmp;
	for(auto p:ver[u]){
		if(p==fa) continue;
		tmp.emplace_back(dfs(p,u));
	}
	
	s+=a[u];
	for(auto pt:tmp){
		s+=max(pt.first,pt.second);
		y+=pt.second;
	}
	y=max(y,0);
	
	for(auto pt:tmp){
		x=max(x,s-max(pt.first,pt.second)+pt.first);
	}
	if(a[u]==1) x=max(x,s);
	
	if(k%2==0&&y>=k){
		ans++;
		return make_pair(0,0);
	}
	
	if(x>=k){
		ans++;
		return make_pair(0,0);
	}
	
	return make_pair(x,y);
}

void solve(){
	cin>>n>>k;
	ans=0;
	a=vector<int>(n+1);
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	
	ver=vector<vector<int>>(n+1);
	for(int i=1; i<n; i++){
		int x,y;
		cin>>x>>y;
		ver[x].emplace_back(y);
		ver[y].emplace_back(x);
	}
	
	dfs(1);
	
	cout<<ans<<'\n';
}

int main(){
	
	cin.tie(0),cout.tie(0)->sync_with_stdio(false);
	
	int T;
	cin>>T;
	while(T--) solve();
	
	return 0;
}

詳細信息

Test #1:

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

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

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: 162ms
memory: 3528kb

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