#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(1e5);
int n, m;
vector<int> vec[N];
bool g[N];
int dfs(int h, int f, int k) {
  if (k > m) return 0;
  if (int(vec[h].size()) == 1 && h != 0) return 1;
  int ans = 0;
  for (int h2 : vec[h]) {
    if (h2 == f) continue;
    int cnt = g[h2] ? k + 1 : 0;
    ans += dfs(h2, h, cnt);
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> g[i];
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  cout << dfs(0, -1, g[0]);
  return 0;
}
