#include <bits/stdc++.h>
using namespace std;
vector<bool> visited;
vector<vector<int>> v;
vector<bool> cats;
int nodes;
int cnt;
int ans = 0;
int catsNum;
void dfs(int x, int cnt) {
  int count = cnt;
  visited[x] = true;
  if (cats[x])
    count++;
  else
    count = 0;
  if (count > catsNum) return;
  if (v[x].size() == 1 && x != 1) ans++;
  for (int i = 0; i < v[x].size(); i++) {
    cnt = count;
    if (!visited[v[x][i]]) {
      dfs(v[x][i], cnt);
    }
  }
}
int main() {
  int exist;
  cin >> nodes;
  visited.resize(nodes + 1);
  v.resize(nodes + 1);
  cats.resize(nodes + 1);
  cin >> catsNum;
  for (int i = 1; i <= nodes; i++) {
    cin >> exist;
    if (exist == 1) cats[i] = true;
  }
  int x, y;
  for (int i = 0; i < nodes - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int initialCnt = 0;
  visited[1] = 1;
  if (cats[1] == true) initialCnt = 1;
  for (int i = 0; i < v[1].size(); i++) {
    if (!visited[v[1][i]]) {
      dfs(v[1][i], initialCnt);
    }
  }
  cout << ans << endl;
  return 0;
}
