-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path580C.cpp
More file actions
executable file
·55 lines (42 loc) · 826 Bytes
/
580C.cpp
File metadata and controls
executable file
·55 lines (42 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Problem Code: 580C
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
int kefa_and_park(int n, int m, vector<int>& a, vector<vector<int>>& adj) {
int cnt = 0;
function<void(int, int, int)> dfs = [&](int s, int par, int cats) {
if (a[s])
cats++;
else
cats = 0;
if (cats > m)
return;
bool is_leaf = true;
for (int u: adj[s])
if (u != par) {
is_leaf = false;
dfs(u, s, cats);
}
if (is_leaf)
cnt++;
};
dfs(0, -1, 0);
return cnt;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<vector<int>> adj(n);
for (int& x: a)
cin >> x;
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
adj[x - 1].push_back(y - 1);
adj[y - 1].push_back(x - 1);
}
cout << kefa_and_park(n, m, a, adj);
return 0;
}