#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, cat[N], u, v, cnt = 0, root = 1, z;
vector<int> adj[N];
bool vis[N] = {0};
void DFS(int x, int p, int c) {
  if (c > m) return;
  if (adj[x].size() == 1 && c <= m && x != root) {
    cnt++;
    return;
  }
  for (auto l : adj[x]) {
    if (l != p) {
      if (cat[l] == 1)
        z = c + 1;
      else
        z = 0;
      DFS(l, x, z);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> cat[i];
  n--;
  while (n--) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if (cat[1] == 1)
    DFS(1, 0, 1);
  else
    DFS(1, 0, 0);
  cout << cnt << endl;
  return 0;
}
