#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 9;
const int INF = 1e9 + 7;
long long power(long long x, long long y) {
  if (y == 0) return 1;
  long long temp = power(x, y / 2);
  if (y % 2 == 1)
    return temp * temp * x;
  else
    return temp * temp;
}
int n, m, x, y, ans = 0;
int a[N];
vector<int> adj[N];
bool vis[N];
void dfs(int u, int parent, int cnt) {
  if (a[u] == 1)
    cnt++;
  else
    cnt = 0;
  if (cnt == m) {
    return;
  }
  if (adj[u].size() == 1 && u != 1) {
    ans++;
  }
  for (auto v : adj[u]) {
    if (v == parent) continue;
    dfs(v, u, cnt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) {
    vis[i] = false;
    cin >> a[i];
  }
  m++;
  for (int i = (1); i <= (n - 1); ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0, 0);
  cout << ans << "\n";
  return 0;
}
