#include <bits/stdc++.h>
using namespace std;
vector<int> g[100007];
int cat[100007];
bool used[100007];
int ans = 0;
void dfs(int v, int m, int go = 0) {
  used[v] = true;
  if (cat[v]) {
    go++;
  } else {
    go = 0;
  }
  bool a = false;
  if (go <= m) {
    a = true;
  }
  bool leaf = true;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (!used[to] && a) {
      dfs(to, m, go);
      leaf = false;
    }
  }
  if (a && leaf) ans++;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> cat[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, m);
  cout << ans << endl;
}
