#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int m;
void dfs(int parent, int s, int cnt, vector<int> &cats,
         vector<vector<int> > &adj) {
  if (cats[s] == 1)
    cnt++;
  else
    cnt = 0;
  if (cnt > m) return;
  if (s != 1 && adj[s].size() == 1) {
    ans++;
    return;
  }
  for (int i : adj[s]) {
    if (i != parent) dfs(s, i, cnt, cats, adj);
  }
}
int main() {
  int n;
  int x, y;
  cin >> n >> m;
  vector<int> cats(n + 1);
  for (int i = 1; i <= n; i++) cin >> cats[i];
  vector<vector<int> > adj(n + 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(0, 1, 0, cats, adj);
  cout << ans << "\n";
  return 0;
}
