#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
inline long long int in() {
  long long int p = 0;
  register char ch = 0;
  while (ch < '0' or ch > '9') {
    ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    p = (p << 1) + (p << 3) + ch - '0';
    ch = getchar();
  }
  return p;
}
long long int n, m, x, y, ar[100005];
vector<long long int> adj[100005];
long long int vis[100005], ans = 0;
void dfs(long long int st, long long int re, long long int co,
         long long int flg) {
  vis[st] = 1;
  if (co > m) flg = 1;
  if (adj[st].size() == 1 && st != 1) {
    if (flg == 1) {
      return;
    } else {
      ans++;
      return;
    }
  }
  for (long long int i = 0; i < adj[st].size(); ++i) {
    if (vis[adj[st][i]] == 0) {
      if (ar[adj[st][i]] == 1) {
        if (re == 1) {
          dfs(adj[st][i], 1, co + 1, flg);
        } else {
          dfs(adj[st][i], 1, 1, flg);
        }
      } else {
        dfs(adj[st][i], 0, 0, flg);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  ar[0] = 0;
  for (long long int i = 0; i < n + 1; i++) {
    if (i > 0) cin >> ar[i];
  }
  for (long long int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  memset(vis, 0, sizeof(vis));
  if (ar[1] == 0)
    dfs(1, 0, 0, 0);
  else
    dfs(1, 1, 1, 0);
  cout << ans << endl;
  return 0;
}
