#include <bits/stdc++.h>
using namespace std;
int c = 0, a[100005], n, m, x, y, j;
vector<int> v[100005];
bool vis[100005];
void dfs(int s, int m1) {
  vis[s] = true;
  if (m1 > m) return;
  if (m1 <= m && v[s].size() == 1 && s != 1) {
    c++;
    return;
  }
  for (int i = 0; i < v[s].size(); i++) {
    if (vis[v[s][i]] == false) {
      if (a[v[s][i]] == 0)
        dfs(v[s][i], 0);
      else
        dfs(v[s][i], m1 + 1);
    }
  }
}
int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    vis[i] = false;
  }
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (a[1] == 1)
    dfs(1, 1);
  else
    dfs(1, 0);
  cout << c;
  return 0;
}
