#include <bits/stdc++.h>
using namespace std;
int par[100001], cats[100001], arr[100001];
char color[100001];
vector<int> adj[100001];
int main() {
  int n, m, i, j, u, v, s, t, cnt, k, temp, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (i = 1; i <= n; i++) {
    color[i] = 'W';
    par[i] = -1;
    cats[i] = 0;
  }
  s = 1;
  cats[s] = arr[s];
  color[s] = 'G';
  queue<int> pq;
  pq.push(s);
  while (pq.size() != 0) {
    u = pq.front();
    pq.pop();
    for (j = 0; j < adj[u].size(); j++) {
      v = adj[u][j];
      if (color[v] == 'W') {
        if (arr[v] == 1) {
          cats[v] = cats[u] + 1;
          if (cats[v] <= m) {
            color[v] = 'G';
            pq.push(v);
          }
        } else {
          cats[v] = 0;
          color[v] = 'G';
          pq.push(v);
        }
      }
    }
    color[u] = 'B';
  }
  cnt = 0;
  for (i = 2; i <= n; i++) {
    if (adj[i].size() == 1 && cats[i] <= m && color[i] != 'W') cnt++;
  }
  cout << cnt << "\n";
  return 0;
}
