#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, m;
int ans, w[MAXN], dp[MAXN];
vector<int> V[MAXN];
void dfs(int u, int pre) {
  if (dp[pre] == -1)
    dp[u] = -1;
  else if (w[u] == 1)
    dp[u] = dp[pre] + 1;
  else
    dp[u] = 0;
  if (dp[u] > m) dp[u] = -1;
  int flag = 1;
  for (int i = 0; i < V[u].size(); i++) {
    int v = V[u][i];
    if (v == pre) continue;
    flag = 0;
    dfs(v, u);
  }
  if (flag && dp[u] != -1) ans++;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &w[i]);
      V[i].clear();
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      V[u].push_back(v);
      V[v].push_back(u);
    }
    memset(dp, 0, sizeof(dp));
    ans = 0;
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
    }
    printf("%d\n", ans);
  }
  return 0;
}
