#include <bits/stdc++.h>
using namespace std;
int n, m, cat[100005], d[100005], dd[100005], ans;
vector<int> a[100005];
void DFS(int u) {
  dd[u] = 1;
  bool kt = 0;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i];
    if (dd[v] == 0) {
      kt = 1;
      if (cat[v] == 0) {
        DFS(v);
      } else {
        d[v] = d[u] + 1;
        if (d[v] <= m) DFS(v);
      }
    }
  }
  if (kt == 0) ans++;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> cat[i];
  }
  int x, y;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  if (cat[1] == 1) d[1] = 1;
  DFS(1);
  cout << ans;
}
