#include <bits/stdc++.h>
const long long N = 1e5 + 5, inf = 2000000000000000000;
using namespace std;
long long int n, m, x, y, k = 0, ans = 0;
long long int vis[N], a[N];
vector<long long int> adj[N];
void dfs(long long int node, long long int k) {
  vis[node] = 1;
  if (a[node]) {
    k++;
  } else
    k = 0;
  if (k > m) return;
  if (adj[node].size() == 1 && node != 0) {
    ans++;
  }
  for (auto it : adj[node]) {
    if (!vis[it]) dfs(it, k);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    cin >> n >> m;
    for (long long int i = 0; i < n; i++) cin >> a[i];
    for (long long int i = 0; i < n - 1; i++) {
      cin >> x >> y;
      x--, y--;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(0, 0);
    cout << ans << '\n';
  }
}
