#include <bits/stdc++.h>
using namespace std;
void pv(vector<long long int> arr, long long int size) {
  for (long long int i = 0; i < size; i++) {
    cout << arr[i] << ' ';
  }
}
void gv(vector<long long int> &arr) {
  long long int size = arr.size();
  for (long long int i = 0; i < size; i++) {
    cin >> arr[i];
  }
}
long long int m;
long long int dfs(long long int v, vector<vector<long long int>> &adj,
                  vector<long long int> &visited, vector<long long int> &arr,
                  long long int k) {
  long long int c = 0, s = 0;
  if (arr[v] == 1)
    k++;
  else
    k = 0;
  if (k > m) return 0;
  visited[v] = 1;
  for (long long int i = 0; i < adj[v].size(); i++) {
    if (visited[adj[v][i]] == 0) {
      c++;
      s += dfs(adj[v][i], adj, visited, arr, k);
    }
  }
  if (c == 0) {
    return 1;
  } else {
    return s;
  }
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, x, y;
  cin >> n >> m;
  vector<long long int> arr(n + 1), visited(n + 1, 0);
  vector<vector<long long int>> adj(n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (long long int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cout << dfs(1, adj, visited, arr, 0);
  return 0;
}
