#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n, m;
int ans = 0;
bool v[maxn];
vector<int> f[maxn];
void dfs(int i, int from, int number) {
  if (v[i])
    number++;
  else
    number = 0;
  if (number > m) return;
  if (f[i].size() == 1 && f[i][0] == from) ans++;
  for (vector<int>::iterator it = f[i].begin(); it != f[i].end(); it++) {
    if (*it != from) dfs(*it, i, number);
  }
  return;
}
int main() {
  int a, b;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    f[a].push_back(b);
    f[b].push_back(a);
  }
  dfs(1, 0, 0);
  cout << ans << endl;
  return 0;
}
