#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100010];
int cats[100010];
bool visited[100010];
int dfs(int node, int c, int maxCats) {
  visited[node] = true;
  if (cats[node])
    c--;
  else
    c = maxCats;
  if (c < 0)
    return 0;
  else {
    int s = graph[node].size();
    bool leaf = true;
    int cont = 0;
    for (int i = 0; i < s; i++) {
      if (!visited[graph[node][i]]) {
        leaf = false;
        cont += dfs(graph[node][i], c, maxCats);
      }
    }
    if (leaf) return 1;
    return cont;
  }
}
int main() {
  memset(visited, false, sizeof visited);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> cats[i];
  int x, y;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  cout << dfs(1, m, m) << '\n';
  return 0;
}
