#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
int n, max_cats;
vector<int> v[maxn];
bool cat[maxn];
int dfs(int x, int p = 0, int cats = 0) {
  if (cats + cat[x] > max_cats) return 0;
  int sum = 0;
  bool bl = 1;
  for (int i : v[x]) {
    if (i == p) continue;
    sum += dfs(i, x, (cat[x] ? cats + 1 : 0));
    bl = 0;
  }
  if (bl) return 1;
  return sum;
}
int x, y;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> max_cats;
  for (int i = 1; i <= n; ++i) cin >> cat[i];
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cout << dfs(1) << '\n';
  return 0;
}
