#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > gr;
vector<int> arr;
int cnt = 0;
int n, d;
void choo(int chld, int pa, int cur) {
  if (arr[chld] == 0)
    cur = 0;
  else
    cur++;
  if (cur > d) return;
  bool isLf = true;
  for (int i = 0; i < gr[chld].size(); i++) {
    if (gr[chld][i] != pa) {
      isLf = false;
      choo(gr[chld][i], chld, cur);
    }
  }
  cnt += isLf;
}
int main() {
  cin >> n >> d;
  arr.resize(n + 1, -1);
  vector<int> fady;
  gr.resize(n, fady);
  int t1, t2;
  for (int i = 0; i < n; i++) {
    cin >> t1;
    arr[i] = t1;
  }
  for (int i = 1; i < n; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    gr[t1 - 1].push_back(t2 - 1);
    gr[t2 - 1].push_back(t1 - 1);
  }
  choo(0, -1, 0);
  cout << cnt << endl;
  return 0;
}
