#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> adj[100005];
vector<int> cat(100005);
int n, m, ans;
void dfs(int c, int p, int count) {
  if (cat[c] == 1) {
    ++count;
  } else
    count = 0;
  int f = 1;
  for (auto x : adj[c]) {
    if (x != p and count <= m) {
      f = 0;
      dfs(x, c, count);
    }
  }
  if (f == 1 and count <= m) ++ans;
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> cat[i];
  }
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cat[0] = 1;
  dfs(1, 0, 0);
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
