#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, mod = 1000000007;
long long int paths = 0, m;
vector<long long int> adj[N], val(N);
void dfs(long long int u, long long int p, long long int curr,
         long long int maxcon) {
  if (val[u]) {
    curr++;
    maxcon = max(maxcon, curr);
  } else {
    maxcon = max(maxcon, curr);
    curr = 0;
  }
  bool leaf = 1;
  for (auto v : adj[u]) {
    if (v != p) {
      dfs(v, u, curr, maxcon);
      leaf = 0;
    }
  }
  if (leaf) {
    paths += (maxcon <= m);
  }
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int pro = 1, temp, t, n, k, i, j, l, r, mid, x, y, z, rem,
                carry = 0, ind, ans = 0, mx = -LONG_LONG_MAX,
                mn = LONG_LONG_MAX, cnt = 0, curr = 0, prev, sum = 0, flag = 1,
                i1 = -1, i2 = -1;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0, 0, 0);
  cout << paths << '\n';
  return 0;
}
