#include <bits/stdc++.h>
using namespace std;
void fast();
long long power(long long n, long long k) {
  long long power = 1;
  for (int i = 0; i < k; i++) {
    power = power * n;
  }
  return power;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int cat[100000 + 50];
long long ans = 0, n, m;
vector<vector<int>> adj(100000 + 50);
void dfs(int cur, int p, int c) {
  if (cat[cur] == 1)
    c++;
  else
    c = 0;
  if (c > m) return;
  int leaf = 1;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == p) continue;
    leaf = 0;
    dfs(adj[cur][i], cur, c);
  }
  if (leaf == 1) ans++;
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> cat[i];
  int x, y;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0, 0);
  cout << ans;
  return 0;
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
