#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n, m;
const int sz = 100005;
vector<vector<int>> x(sz);
vector<bool> hasCat(sz);
vector<int> visited(sz);
int dfs(int i, int prev, int cats) {
  if (cats > m) return 0;
  if (x[i].empty() || (x[i].size() == 1 && prev != -1)) {
    return 1;
  }
  visited[i] = true;
  int ans = 0;
  for (auto &j : x[i]) {
    if (!visited[j]) {
      if (j == prev || visited[j]) continue;
      if (hasCat[j]) {
        ans += dfs(j, i, cats + 1);
      } else {
        ans += dfs(j, i, 0);
      }
    }
  }
  return ans;
}
void solve() {
  scanf("%d%d", &n, &m);
  bool temp;
  for (int i = 1; i <= n; i++) {
    cin >> temp;
    hasCat[i] = temp;
  }
  int f, t;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &f, &t);
    x[f].push_back(t);
    x[t].push_back(f);
  }
  cout << dfs(1, -1, hasCat[1]);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
