#include <bits/stdc++.h>
using namespace std;
long long fast(long long a, long long b) {
  long long ans = 1;
  a = a % 1000000007;
  if (a == 0) return 0;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % 1000000007;
    }
    b >>= 1;
    a = (a * a) % 1000000007;
  }
}
const long long MAX = 1000000;
long long prime[MAX + 5];
void sieve() {
  for (long long i = 2; i * i <= MAX; i++) {
    if (prime[i] == 0) {
      for (long long j = i * i; j <= MAX; j += i) {
        prime[j] = 1;
      }
    }
  }
}
vector<long long> v[1000005];
long long ans = 0, n, m;
long long c[100005];
long long visited[100005];
void dfs(long long parent, long long k) {
  visited[parent] = 1;
  if (c[parent] == 1)
    k++;
  else
    k = 0;
  if (k > m) return;
  long long flag = 1;
  for (auto child : v[parent]) {
    if (!visited[child]) {
      flag = 0;
      dfs(child, k);
    }
  }
  if (flag == 1) {
    ans++;
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) cin >> c[i];
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans << "\n";
  return 0;
}
