#include <bits/stdc++.h>
using namespace std;
vector<long long> g[100000];
bool used[100000];
long long kot1[100000];
bool kot[100000];
void dfs(long long v, long long pr, long long cnt, bool x) {
  long long cnt1 = cnt;
  bool z = kot[v];
  if (pr != -1) {
    if (z) {
      cnt1++;
    } else {
      cnt1 = 0;
    }
    kot1[v] = max(cnt1, kot1[pr]);
  }
  used[v] = true;
  for (auto i : g[v]) {
    if (!used[i]) {
      dfs(i, v, cnt1, z);
    }
  }
}
int32_t main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    bool x;
    cin >> x;
    kot[i] = x;
  }
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long ans = 0;
  kot1[0] = kot[0];
  dfs(0, -1, kot1[0], 0);
  for (long long i = 0; i < n; i++) {
    if (g[i].size() == 1 && kot1[i] <= k && i != 0) {
      ans++;
    }
  }
  cout << ans;
}
