#include <bits/stdc++.h>
using namespace std;
bool vis[100005];
vector<int> v[100005];
int n, m, a[100005], ans = 0;
void dfs(int x, int cnt) {
  if (vis[x]) return;
  vis[x] = 1;
  if (a[x]) cnt++;
  if (cnt > m) return;
  if (!a[x]) cnt = 0;
  for (int j = 0; j < v[x].size(); j++) dfs(v[x][j], cnt);
  if (v[x].size() == 1 && x != 1) ans++;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int b, c;
    cin >> b >> c;
    v[b].push_back(c);
    v[c].push_back(b);
  }
  dfs(1, 0);
  cout << ans;
}
