#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long ZERO = 0;
const long long SADAT = 7.84e-17;
const long long INF = 1e9;
const long long mod = 1e9 + 7;
int n, m;
bool cat[maxn];
vector<int> vec[maxn];
int val[maxn];
int cnt = 0;
bool mark[maxn];
void dfs(int v) {
  if (cat[v - 1]) {
    val[v]++;
  } else if (val[v] <= m) {
    val[v] = 0;
  }
  mark[v] = 1;
  bool f = 0;
  for (int u = 0; u < vec[v].size(); u++) {
    if (!mark[vec[v][u]]) {
      val[vec[v][u]] = max(val[vec[v][u]], val[v]);
      dfs(vec[v][u]);
      f = 1;
    }
  }
  if (f == 0) {
    if (val[v] <= m) {
      cnt++;
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fill(val, val + maxn, 0);
  fill(cat, cat + maxn, 0);
  fill(mark, mark + maxn, 0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> cat[i];
  }
  int x, y;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  dfs(1);
  cout << cnt;
  return (0);
}
