#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
bool seq[100005], seen[100005];
int n, m, u, v;
int dfs(int u, int cnt) {
  seen[u] = true;
  int sum = 0;
  if (seq[u] == 1 && cnt > 0)
    sum = 1 + cnt;
  else
    sum = seq[u];
  if (sum > m) return 0;
  int ans = 0;
  bool child = false;
  for (int to : G[u])
    if (seen[to] == 0) {
      ans += dfs(to, sum);
      child = true;
    }
  if (!child) return 1;
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> u;
    seq[i + 1] = u;
  }
  memset(seen, 0, sizeof seen);
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  cout << dfs(1, 0) << endl;
  return 0;
}
