#include <bits/stdc++.h>
using namespace std;
int n, m, aux, aux2;
int ans = 0;
bool cat[100005];
vector<int> tree[100005];
int cats[100005];
void dfs(int node, int parent) {
  if (tree[node].size() == 1 && node != 1 && cats[node] <= m) ans++;
  for (int i : tree[node]) {
    if (i == parent) continue;
    if (cat[i] || cats[node] > m) cats[i] = cats[node] + 1;
    dfs(i, node);
  }
}
int main() {
  memset(cats, 0, sizeof(cats));
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> aux;
    cat[i] = aux;
  }
  for (int i = 1; i < n; i++) {
    cin >> aux >> aux2;
    tree[aux].push_back(aux2);
    tree[aux2].push_back(aux);
  }
  cats[1] = cat[1];
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
