#include <bits/stdc++.h>
using namespace std;
int n, m, countcat[200001], ans = 0, visited[200001] = {0};
std::vector<int> v[200001];
void dfs(int node, int num) {
  visited[node]++;
  if (num > m)
    return;
  else {
    int flag = 0;
    for (int i = 0; i < v[node].size(); i++)
      if (!visited[v[node][i]]) {
        flag = 1;
        if (countcat[v[node][i]])
          dfs(v[node][i], num + 1);
        else
          dfs(v[node][i], 0);
      }
    if (!flag && num <= m) ans++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> countcat[i + 1];
  int x, y;
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, countcat[1]);
  cout << ans << "\n";
  return 0;
}
