#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;else
if (power[x])d[x]=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+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8c3RhY2s+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8cXVldWU+CiNpbmNsdWRlPHNzdHJlYW0+CiNpbmNsdWRlPGN0eXBlLmg+CiNpbmNsdWRlPG1lbW9yeS5oPgojaW5jbHVkZTxzdGRsaWIuaD4KI2luY2x1ZGU8ZnN0cmVhbT4KI2luY2x1ZGU8c2V0PgojaW5jbHVkZTxzdGRpby5oPgojaW5jbHVkZTxiaXRzZXQ+CiNpbmNsdWRlPG1hcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgdmlzWzExMTExMV07CmludCBkWzExMTExMV07CmludCBwb3dlclsxMTExMTFdOwp2ZWN0b3I8aW50PiB2WzExMTExMV07CmludCBjbnQ7CmludCBuLCBtOwoKdm9pZCBiZnMoaW50IHgpewogICAgcXVldWU8aW50PiBxOwogICAgcS5wdXNoKHgpOwogICAgdmlzW3hdID0gMTsKICAgIGlmIChwb3dlclt4XSA9PSAxKQogICAgICAgIGRbeF0gPSAxOwogICAgd2hpbGUgKCFxLmVtcHR5KCkpewogICAgICAgIGludCBuID0gcS5mcm9udCgpOwogICAgICAgIHEucG9wKCk7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCAoaW50KXZbbl0uc2l6ZSgpOyBpKyspewogICAgICAgICAgICBpbnQgeCA9IHZbbl1baV07CiAgICAgICAgICAgIGlmICghdmlzW3hdKXsKICAgICAgICAgICAgICAgIGlmIChwb3dlclt4XSAmJiBwb3dlcltuXSkKICAgICAgICAgICAgICAgICAgICBkW3hdID0gZFtuXSArIDE7ZWxzZQogICAgICAgICAgICAgICAgICAgIGlmIChwb3dlclt4XSlkW3hdPTE7CiAgICAgICAgICAgICAgICB2aXNbeF0gPSAxOwogICAgICAgICAgICAgICAgaWYgKGRbeF0gPD0gbSl7CiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHgpOwogICAgICAgICAgICAgICAgICAgIGlmICh2W3hdLnNpemUoKSA9PSAxKQogICAgICAgICAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKXsKICAgLy8gZnJlb3BlbigiaW5wdXQuaW4iLCAiciIsIHN0ZGluKTsKICAgIHNjYW5mKCIlZCVkIiwgJm4sICZtKTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICBzY2FuZigiJWQiLCAmcG93ZXJbaV0pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPG4tMTsgaSsrKXsKICAgICAgICBpbnQgYSwgYjsKICAgICAgICBzY2FuZigiJWQlZCIsICZhLCAmYik7CiAgICAgICAgLS1hLCAtLWI7CiAgICAgICAgdlthXS5wdXNoX2JhY2soYik7CiAgICAgICAgdltiXS5wdXNoX2JhY2soYSk7CiAgICB9CiAgICBiZnMoMCk7CiAgICBwcmludGYoIiVkIiwgY250KTsKCiAgICByZXR1cm4gMDsKfQo=