#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> catcheck(n + 1);
  for (int i = 1; i <= n; i++) cin >> catcheck[i];
  vector<int> adjtree[100001];
  int xx, yy;
  for (int i = 0; i < n - 1; i++) {
    cin >> xx >> yy;
    adjtree[xx].push_back(yy);
    adjtree[yy].push_back(xx);
  }
  int ans = 0;
  stack<pair<int, int> > dfs;
  dfs.push({1, 0});
  bool leaf = true;
  while (!dfs.empty()) {
    leaf = true;
    int first = dfs.top().first;
    int second = dfs.top().second;
    dfs.pop();
    for (auto& x : adjtree[first])
      if (catcheck[x] >= 0) {
        leaf = false;
        if (catcheck[first] == 0) dfs.push({x, 0});
        if (catcheck[first] == 1)
          if (second < m) dfs.push({x, second + 1});
      }
    if (leaf)
      if (catcheck[first] == 0) ans++;
    if (leaf)
      if (catcheck[first] == 1)
        if (second < m) ans++;
    catcheck[first] = -1;
  }
  cout << ans << "\n";
  return 0;
}
