#include <bits/stdc++.h>
using namespace std;
vector<bool> visited(100008, false);
vector<int> v(100008);
vector<int> adjList[100008];
vector<int> max_so_far(100008, 0);
vector<int> current_cnt(100008, 0);
void dfs(int source, int parent) {
  if (parent != -1) {
    if (v[source] == 0) {
      max_so_far[source] = max_so_far[parent];
      current_cnt[source] = 0;
    } else {
      if (v[parent] == 1) {
        current_cnt[source] = current_cnt[parent] + 1;
        max_so_far[source] = max_so_far[parent];
        if (current_cnt[source] > max_so_far[source])
          max_so_far[source] = current_cnt[source];
      } else {
        max_so_far[source] = max_so_far[parent];
        current_cnt[source]++;
      }
    }
  }
  visited[source] = true;
  for (int x : adjList[source]) {
    if (!visited[x]) dfs(x, source);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adjList[u].emplace_back(v);
    adjList[v].emplace_back(u);
  }
  max_so_far[1] = v[1];
  current_cnt[1] = v[1];
  dfs(1, -1);
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if ((int)adjList[i].size() == 1) {
      if (max_so_far[i] <= c) ans++;
    }
  }
  cout << ans << "\n";
}
