QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725607#7684. Sweet SugarCode_quantumWA 145ms31048kbC++14938b2024-11-08 19:03:162024-11-08 19:03:20

Judging History

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

  • [2024-11-08 19:03:20]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:31048kb
  • [2024-11-08 19:03:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int inf = 1e7;
const int N = 1000005;
int n, k, ans, c[N], f[N][2]; 
vector<int> g[N]; bool ban[N];

void dfs(int u, int fa){
	if(c[u] % 2 == 0) f[u][0] = c[u], f[u][1] = -inf;
	else f[u][0] = -inf, f[u][1] = c[u];
	for(auto v: g[u]) if(v != fa){
		dfs(v, u); if(ban[v]) continue;
		int t0 = f[u][0], t1 = f[u][1];
		f[u][0] = max(t0 + f[v][0], t1 + f[v][1]);
		f[u][1] = max(t0 + f[v][1], t1 + f[v][0]);
	}
//	if(u == 5) cout << f[u][1] << "qaq" << endl;
	if(f[u][k % 2] >= k){ban[u] = true; ans ++;}
}
void work(){
	scanf("%d %d", &n, &k); ans = 0;
	for(int i = 1; i <= n; i ++) scanf("%d", &c[i]), g[i].clear(), ban[i] = false;
	for(int i = 1; i < n; i ++){
		int u, v; scanf("%d %d", &u, &v);
		g[u].pb(v); g[v].pb(u);
	}
	dfs(1, 0); printf("%d\n", ans);
}
int main(){
	int t; scanf("%d", &t);
	while(t --) work(); return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 30896kb

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: 6ms
memory: 30820kb

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: 145ms
memory: 31048kb

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'