#include <bits/stdc++.h>
typedef struct Node {
  int i;
  struct Node *next;
} Node;
void putin(int, int);
void dfs(int, int);
Node *nei[100005];
int cat[100005], count, n, m, done[100005];
int main() {
  int i, j;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", cat + i);
    nei[i] = NULL;
    done[i] = 0;
  }
  n--;
  while (n--) {
    scanf("%d %d", &i, &j);
    i--;
    j--;
    putin(j, i);
    putin(i, j);
  }
  count = 0;
  dfs(0, 0);
  printf("%d\n", count);
  return 0;
}
void putin(int x, int y) {
  Node *t = (Node *)malloc(sizeof(Node));
  t->i = x;
  t->next = nei[y];
  nei[y] = t;
}
void dfs(int ind, int c) {
  Node *tmp;
  if (cat[ind]) {
    c++;
  } else {
    c = 0;
  }
  if (c > m) return;
  done[ind] = 1;
  tmp = nei[ind];
  if (tmp == NULL || (tmp->next == NULL && done[tmp->i])) count++;
  while (tmp != NULL) {
    if (!done[tmp->i]) dfs(tmp->i, c);
    tmp = tmp->next;
  }
}
