#include <bits/stdc++.h>
using namespace std;
int cat_nodes[100001] = {0};
vector<int> v[100001];
int visited[100001] = {0};
int leaf[100001] = {1};
int ans = 0;
int n, m;
void DFS(int n, int c) {
  visited[n] = 1;
  int flag = 1;
  if (cat_nodes[n] == 0)
    c = 0;
  else
    c++;
  for (auto x : v[n]) {
    if (!visited[x] && cat_nodes[x] + c <= m) {
      flag = 0;
      DFS(x, c);
    }
  }
  if (n != 1 && leaf[n] == 1) {
    ans++;
  }
  visited[n] = 2;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> cat_nodes[i];
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    leaf[x]++;
    leaf[y]++;
  }
  DFS(1, 0);
  cout << ans;
  return 0;
}
