#include <bits/stdc++.h>
using namespace std;
long long int m = 0;
long long int ans = 0;
void dfs(set<long long int> s[], bool visited[], long long int v,
         long long int a[], long long int cats);
int main() {
  long long int n, i, j, t, x, y;
  cin >> n >> m;
  long long int a[n + 1];
  bool visited[n + 1];
  a[0] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int possible[n + 1];
  for (i = 0; i <= n; i++) {
    possible[i] = 1;
  }
  set<long long int> *s = new set<long long int>[n + 1];
  s[0].insert(0);
  n--;
  while (n--) {
    cin >> x >> y;
    s[x].insert(y);
    s[y].insert(x);
  }
  memset(visited, false, sizeof(visited));
  dfs(s, visited, 1, a, 0);
  cout << ans;
  return 0;
}
void dfs(set<long long int> s[], bool visited[], long long int v,
         long long int a[], long long int cats) {
  if (a[v] == 1) {
    cats++;
  } else {
    cats = 0;
  }
  if (cats > m) return;
  if (s[v].size() == 1 && v != 1) ans++;
  visited[v] = true;
  set<long long int>::iterator it;
  for (it = s[v].begin(); it != s[v].end(); ++it) {
    if (!visited[*it]) {
      dfs(s, visited, *it, a, cats);
    }
  }
}
