#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int count1 = 0;
int a[200010];
vector<int> v[200010];
int visited[200010];
void dfs(int i, int value) {
  if (value > m) {
    return;
  }
  if (v[i].size() == 1 and i != 1) {
    count1++;
  }
  for (int j = 0; j < v[i].size(); j++) {
    if (!visited[v[i][j]]) {
      visited[v[i][j]] = 1;
      if (a[v[i][j]] == 1)
        dfs(v[i][j], value + 1);
      else
        dfs(v[i][j], 0);
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  memset(visited, 0, sizeof visited);
  visited[1] = 1;
  if (a[1] == 1)
    dfs(1, 1);
  else
    dfs(1, 0);
  cout << count1 << endl;
  return 0;
}
