#include <bits/stdc++.h>
using namespace std;
bool arr[100005];
vector<int> v[100005];
int visited[100005];
int n, m, a, b, coun = 0;
void dfs(int node, int p, int from) {
  visited[node] = 1;
  int f = 0;
  if (arr[node]) {
    if ((p + 1) <= m) {
      f = 0;
    } else
      f = 1;
  }
  if (f == 1) return;
  int len = v[node].size();
  if (f == 0) {
    for (int i = 0; i < len; i++) {
      if (!visited[v[node][i]]) {
        if (arr[node])
          dfs(v[node][i], p + 1, node);
        else
          dfs(v[node][i], 0, node);
      }
    }
  }
  if (len == 1) {
    if (v[node][0] == from) {
      if (arr[node] && p + 1 <= m) {
        coun++;
      } else if (p <= m)
        coun++;
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= n - 1; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0, -1);
  cout << coun << "\n";
  return 0;
}
