#pragma warning (disable : 4996)
#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<sstream>
#include<ctype.h>
#include<memory.h>
#include<stdlib.h>
#include<fstream>
#include<set>
#include<stdio.h>
#include<bitset>
#include<map>
using namespace std;
int vis[111111];
int d[111111];
int power[111111];
vector<int> v[111111];
int cnt;
int n, m;
void bfs(int x){
queue<int> q;
q.push(x);
vis[x] = 1;
if (power[x] == 1)
d[x] = 1;
while (!q.empty()){
int n = q.front();
q.pop();
for (int i = 0; i < (int)v[n].size(); i++){
int x = v[n][i];
if (!vis[x]){
if (power[x] && power[n])
d[x] = d[n] + 1;
vis[x] = 1;
if (d[x] <= m){
q.push(x);
if (v[x].size() == 1)
cnt++;
}
}
}
}
}
int main(){
// freopen("input.in", "r", stdin);
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &power[i]);
for (int i = 0; i <n-1; i++){
int a, b;
scanf("%d%d", &a, &b);
--a, --b;
v[a].push_back(b);
v[b].push_back(a);
}
bfs(0);
printf("%d", cnt);
return 0;
}
I3ByYWdtYSB3YXJuaW5nIChkaXNhYmxlIDogNDk5NikKI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4gCiNpbmNsdWRlPHN0YWNrPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxzc3RyZWFtPgojaW5jbHVkZTxjdHlwZS5oPgojaW5jbHVkZTxtZW1vcnkuaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPGZzdHJlYW0+CiNpbmNsdWRlPHNldD4KI2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8Yml0c2V0PgojaW5jbHVkZTxtYXA+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKaW50IHZpc1sxMTExMTFdOwppbnQgZFsxMTExMTFdOwppbnQgcG93ZXJbMTExMTExXTsKdmVjdG9yPGludD4gdlsxMTExMTFdOwppbnQgY250OwppbnQgbiwgbTsKCnZvaWQgYmZzKGludCB4KXsKICAgIHF1ZXVlPGludD4gcTsKICAgIHEucHVzaCh4KTsKICAgIHZpc1t4XSA9IDE7CiAgICBpZiAocG93ZXJbeF0gPT0gMSkKICAgICAgICBkW3hdID0gMTsKICAgIHdoaWxlICghcS5lbXB0eSgpKXsKICAgICAgICBpbnQgbiA9IHEuZnJvbnQoKTsKICAgICAgICBxLnBvcCgpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgKGludCl2W25dLnNpemUoKTsgaSsrKXsKICAgICAgICAgICAgaW50IHggPSB2W25dW2ldOwogICAgICAgICAgICBpZiAoIXZpc1t4XSl7CiAgICAgICAgICAgICAgICBpZiAocG93ZXJbeF0gJiYgcG93ZXJbbl0pCiAgICAgICAgICAgICAgICAgICAgZFt4XSA9IGRbbl0gKyAxOwogICAgICAgICAgICAgICAgdmlzW3hdID0gMTsKICAgICAgICAgICAgICAgIGlmIChkW3hdIDw9IG0pewogICAgICAgICAgICAgICAgICAgIHEucHVzaCh4KTsKICAgICAgICAgICAgICAgICAgICBpZiAodlt4XS5zaXplKCkgPT0gMSkKICAgICAgICAgICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCl7CiAgIC8vIGZyZW9wZW4oImlucHV0LmluIiwgInIiLCBzdGRpbik7CiAgICBzY2FuZigiJWQlZCIsICZuLCAmbSk7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCiAgICAgICAgc2NhbmYoIiVkIiwgJnBvd2VyW2ldKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDxuLTE7IGkrKyl7CiAgICAgICAgaW50IGEsIGI7CiAgICAgICAgc2NhbmYoIiVkJWQiLCAmYSwgJmIpOwogICAgICAgIC0tYSwgLS1iOwogICAgICAgIHZbYV0ucHVzaF9iYWNrKGIpOwogICAgICAgIHZbYl0ucHVzaF9iYWNrKGEpOwogICAgfQogICAgYmZzKDApOwogICAgcHJpbnRmKCIlZCIsIGNudCk7CgogICAgcmV0dXJuIDA7Cn0K