#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
inline int reint() {
  int d;
  scanf("%d", &d);
  return d;
}
inline long relong() {
  long l;
  scanf("%ld", &l);
  return l;
}
inline char rechar() {
  scanf(" ");
  return getchar();
}
inline double redouble() {
  double d;
  scanf("%lf", &d);
  return d;
}
inline string restring() {
  string s;
  cin >> s;
  return s;
}
const int maxn = 1e5 + 10;
int n, m;
int c[maxn];
int vis[maxn];
int cat[maxn];
vector<int> v[maxn];
int dfs(int a, int prev_cat) {
  vis[a] = 1;
  if (prev_cat > m) return 0;
  int s = v[a].size();
  if (s == 1 && vis[v[a][0]]) {
    if (c[a] && prev_cat >= m) {
      return 0;
    } else {
      return 1;
    }
  }
  if (c[a])
    cat[a] = prev_cat + 1;
  else
    cat[a] = 0;
  int ans = 0;
  for (int i = (0); i < (v[a].size()); i++) {
    if (!vis[v[a][i]]) {
      ans += dfs(v[a][i], cat[a]);
    }
  }
  return ans;
}
int main(void) {
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) {
    cin >> c[i];
  }
  int a, b;
  for (int i = (0); i < (n - 1); i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  cat[1] = c[1];
  vis[1] = 1;
  int ans = dfs(1, 0);
  cout << ans << endl;
  return 0;
}
