#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main() {
  int n, m, a, b;
  cin >> n >> m;
  int sol = 0;
  vector<int> v;
  vector<int> time(n + 1);
  vector<set<int> > g(n + 1);
  vector<int> cum(n + 1);
  v.push_back(0);
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[b].insert(a);
    g[a].insert(b);
  }
  std::queue<int> q;
  q.push(1);
  cum[1] = v[1];
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    time[t] = 1;
    if (g[t].size() == 0) {
      sol++;
    } else {
      for (auto i : g[t]) {
        if (time[i] == 0) {
          g[i].erase(t);
          if (v[i] == 0) {
            q.push(i);
          } else {
            if (cum[t] + 1 <= m) {
              cum[i] = cum[t] + 1;
              q.push(i);
            }
          }
        }
      }
    }
  }
  cout << sol;
}
