#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define faster() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define mod 1000000007
int n , m , res = 0;
vector<int> adj[1005];
bool visited[1005];
int d[1005];// chi luu 0 , 1 dai dien khong hoac co con gian
void DFS(int u, int cnt){
if(cnt > m) return ;
bool check = false ;
visited[u] = true ;
for(int v : adj[u]){
if(!visited[v]){
check = true ; // day chua phai la node la
if(!d[v]) DFS(v , 0); // dem so 0 lien tuc neu gap so 0 thi reset lai
else DFS(v , cnt + 1);
}
}
if(check == false) res++ ; // kiem tra xem co bao nhieu node la(khong di tiep dc)
}
void solve() {
cin >> n >> m ;
for(int i = 1 ; i <= n ; i++){
cin >> d[i];
}
for(int i = 1 ; i <= n - 1 ; i++){
int x , y ; cin >> x >> y ;
adj[x].push_back(y);
adj[y].push_back(x);
}
DFS(1 , d[1]);// d[1] = 0 || d[1] = 1
cout << res << endl;
}
signed main(){
faster();
int test = 1 ;
// cin >> test ;
while(test--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZW5kbCAiXG4iCiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIGZhc3RlcigpIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZShudWxscHRyKTsgY291dC50aWUobnVsbHB0cik7CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKCmludCBuICwgbSAsIHJlcyA9IDA7IAp2ZWN0b3I8aW50PiBhZGpbMTAwNV07CmJvb2wgdmlzaXRlZFsxMDA1XTsKaW50IGRbMTAwNV07Ly8gY2hpIGx1dSAwICwgMSBkYWkgZGllbiBraG9uZyBob2FjIGNvIGNvbiBnaWFuCnZvaWQgREZTKGludCB1LCBpbnQgY250KXsKICAgIGlmKGNudCA+IG0pIHJldHVybiA7CiAgICBib29sIGNoZWNrID0gZmFsc2Ug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