#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(100005), vv(100005);
int a[100005];
int n, m, ans;
void dfs(int node, int cats) {
  if (cats > m) return;
  if (vv[node].size() == 0) ans++;
  for (int i = 0; i < vv[node].size(); i++) {
    int x = vv[node][i];
    dfs(x, a[x - 1] ? cats + 1 : 0);
  }
}
void bfsfill() {
  bool vis[100005] = {0};
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = 1;
    for (int i = 0; i < v[x].size(); i++)
      if (!vis[v[x][i]]) {
        vv[x].push_back(v[x][i]);
        q.push(v[x][i]);
      }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfsfill();
  dfs(1, a[0]);
  cout << ans << "\n";
  return 0;
}
