#include <bits/stdc++.h>
using namespace std;
long long const INF = 1000000007;
int vis[100001];
vector<int> adj[100001];
int a[100001];
int ans;
int n, m, k;
void dfs(int v, int k) {
  vis[v] = 1;
  if (a[v] == 1)
    k++;
  else
    k = 0;
  if (k > m) return;
  if (adj[v].size() == 1 && v != 1) {
    ans++;
    return;
  }
  for (auto child : adj[v]) {
    if (!vis[child]) dfs(child, k);
  }
}
void solve() {
  cin >> n >> m;
  int i;
  for (i = 1; i <= n; i++) {
    vis[i] = 0;
    adj[i].clear();
    a[i] = 0;
  }
  for (i = 1; i <= n; i++) cin >> a[i];
  int u, v;
  for (i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ans = 0;
  dfs(1, 0);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
