#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
int n, m;
vector<int> a, adj[sz];
bool vis[sz];
void dfs(int p, int &ans, int cnt) {
  vis[p] = 1;
  if (a[p])
    ++cnt;
  else if (cnt <= m)
    cnt = 0;
  bool last = true;
  for (int i = 0; i < adj[p].size(); i++) {
    if (!vis[adj[p][i]]) {
      last = false;
      dfs(adj[p][i], ans, cnt);
    }
  }
  if (last && cnt <= m) ++ans;
}
int main() {
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    vis[sz] = 0;
    adj[i].clear();
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int ans = 0;
  dfs(0, ans, 0);
  cout << ans << "\n";
  return 0;
}
