#include <bits/stdc++.h>
using namespace std;
int n, m, a[int(1e5 + 1)];
vector<int> h[int(1e5) + 1];
bool isLeaf(int u, bool Free[]) {
  for (int i = 0; i < h[u].size(); i++) {
    if (Free[h[u][i]]) return false;
  }
  return true;
}
int DFS(int prev, int u, bool Free[], int cnt, int mmax) {
  Free[u] = false;
  if (isLeaf(u, Free)) {
    if (a[u] == a[prev] && a[u] == 1) cnt++;
    mmax = max(mmax, cnt);
    return (mmax > m ? 0 : 1);
  }
  int res = 0;
  for (int i = 0; i < h[u].size(); i++) {
    if (Free[h[u][i]]) {
      if (a[u] == a[prev]) {
        if (a[u] == 1)
          res += DFS(u, h[u][i], Free, cnt + 1, mmax);
        else
          res += DFS(u, h[u][i], Free, 0, mmax);
      } else if (a[u] != a[prev]) {
        if (a[u] == 1)
          res += DFS(u, h[u][i], Free, 1, mmax);
        else
          res += DFS(u, h[u][i], Free, 0, max(mmax, cnt));
      }
    }
  }
  return res;
}
int main() {
  bool Free[int(1e5 + 1)];
  for (int i = 0; i < int(1e5 + 1); i++) Free[i] = true;
  Free[1] = false;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  a[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    h[x].push_back(y), h[y].push_back(x);
  }
  cout << DFS(0, 1, Free, 0, 0);
  return 0;
}
