#include <bits/stdc++.h>
using namespace std;
vector<long long> g[100100];
bool us[100100], a[100100];
long long k, m, ans;
void dfs(long long s, long long kol) {
  if (a[s] == 0)
    kol = 0;
  else
    kol++;
  if (kol > m) return;
  if (g[s].size() == 1 && s != 1) ans++;
  for (int i = 0; i < g[s].size(); i++) {
    if (!us[g[s][i]]) {
      us[g[s][i]] = 1;
      dfs(g[s][i], kol);
    }
  }
}
long long n, i, j, ost, mx, dp[100010], r, l, b[100010], prediction, s, x, y,
    mid, c;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  us[1] = 1;
  dfs(1, 0);
  cout << ans;
  return 0;
}
