#include <bits/stdc++.h>
using namespace std;
long long vis[100005], cat[100005], n, m, ans;
vector<long long> graph[100005];
long long isleaf(long long n) {
  if (graph[n].size() == 1) return true;
  return false;
}
void dfs(long long node, long long &cnt, long long par) {
  vis[node] = 1;
  if (isleaf(node) and par != -1) {
    if (cnt <= m) ans++;
    return;
  }
  for (long long i = 0; i < graph[node].size(); ++i) {
    long long cnt1 = cnt, curr = graph[node][i];
    if (vis[curr] != 1) {
      if (cat[curr] == 1)
        cnt1++;
      else
        cnt1 = 0;
      if (cnt1 <= m) dfs(curr, cnt1, node);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test, i, j;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    cin >> cat[i];
  }
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  long long c = cat[1];
  dfs(1, c, -1);
  cout << ans << "\n";
}
