#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 10, oo = 1e9 + 7;
long long n, m;
vector<long long> adj[M], vis(M, 0), cts(M, 0);
void dfs(long long s, long long cr, long long mx) {
  if (mx > m) return;
  vis[s] = 1;
  for (auto v : adj[s]) {
    if (!vis[v]) {
      long long k = 0;
      if (cts[v]) k = cr + 1;
      dfs(v, k, max(mx, k));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> cts[i];
  for (long long i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, cts[1], cts[1]);
  long long cnt = 0;
  for (int i = 2; i <= n; i++) {
    if (adj[i].size() == 1 && vis[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
