#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int n, m, a[N], vis[N] = {0}, ans = 0;
vector<int> adj[N];
void dfs(int parent, int cat) {
  if (vis[parent] || cat > m) return;
  vis[parent] = 1;
  for (auto child : adj[parent]) {
    if (a[child] == 1)
      dfs(child, cat + 1);
    else
      dfs(child, 0);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, a[1]);
  for (int i = 2; i <= n; i++) {
    if (adj[i].size() == 1 and vis[i]) ans++;
  }
  cout << ans << endl;
}
