#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], x, y, res = 0;
vector<int> adj[100005];
bool visited[100005];
bool visited2[100005];
void initialize() {
  for (int i = 0; i < n; i++) {
    visited[i + 1] = false;
  }
  for (int i = 0; i < n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
}
void dfs(int s, int k, int r) {
  if (k > m) return;
  if (s == 1) {
    if (a[s - 1] == 1) k++;
  }
  visited[s] = true;
  int f = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    if (adj[s][i] != r) {
      f = 0;
      if (visited[adj[s][i]] == false) {
        if (a[adj[s][i] - 1] == 1)
          dfs(adj[s][i], k + 1, s);
        else
          dfs(adj[s][i], 0, s);
      }
    }
  }
  res += f;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d ", &a[i]);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  initialize();
  dfs(1, 0, -1);
  printf("%d\n", res);
  return 0;
}
