-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkefandpark.cpp
More file actions
executable file
·60 lines (54 loc) · 1022 Bytes
/
kefandpark.cpp
File metadata and controls
executable file
·60 lines (54 loc) · 1022 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
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define SIZE 100002
ll power(ll a, ll b) {
ll x = 1, y = a;
while(b > 0) {
if(b%2 == 1) {
x=(x*y);
if(x>mod) x%=mod;
}
y = (y*y);
if(y>mod) y%=mod;
b /= 2;
}
return x;
}
vector<ll> adj[SIZE];
bool visited[SIZE];
int cats[SIZE], ans, m;
void dfs(int r, int catcount)
{
if(cats[r]) catcount++;
else catcount=0;
if(catcount<=m){
if(r>1 && adj[r].size()==1 && catcount<=m) ans++;
visited[r]=true;
for(int i=0; i<adj[r].size(); i++)
{
if(!visited[adj[r][i]])
{
dfs(adj[r][i], catcount);
}
}
}
}
int main(void){
int n;
cin>>n>>m;
memset(visited, 0, sizeof(visited));
for(int i=1; i<=n; i++) cin>>cats[i];
for(int i=0; i<n-1; i++)
{
int u, v; cin>>u>>v;
adj[u].pb(v); adj[v].pb(u);
}
int ct=0;
dfs(1, ct);
cout<<ans<<"\n";
return 0;
}