#include <bits/stdc++.h>
using namespace std;
vector<int> tree[100005];
int cat[100005];
bool vis[100005];
int n, m, ans = 0;
void dfs(int root, int num) {
  vis[root] = true;
  if (cat[root])
    num++;
  else
    num = 0;
  if (num > m) return;
  if (tree[root].size() == 1 && vis[tree[root][0]]) {
    ans++;
    return;
  }
  for (int i = 0; i < tree[root].size(); i++) {
    int c = tree[root][i];
    if (!vis[c]) dfs(c, num);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &cat[i]);
  for (int i = 0; i < n - 1; i++) {
    int f, s;
    scanf("%d %d", &f, &s);
    tree[f].push_back(s);
    tree[s].push_back(f);
  }
  dfs(1, 0);
  cout << ans << endl;
}
