#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
  if (x <= 1) return false;
  if (x <= 3) return true;
  if (x % 2 == 0 || x % 3 == 0) return false;
  for (long long int i = 5; i * i <= x; i += 6) {
    if (x % i == 0 || x % (i + 2) == 0) return false;
  }
  return true;
}
long long int nextPrime(int x) {
  if (x <= 1) return 2;
  while (!isPrime(x)) {
    x++;
  }
  return x;
}
int gcd(int a, int b) {
  while (a != 0) {
    int temp = a;
    a = b % a;
    b = temp;
  }
  return b;
}
long long int myceil(long long int a, long long int b) {
  return a / b + (a % b != 0);
}
long long int logabaseb(long long int a, long long int b) {
  long long int i = 1;
  long long int ans = 0;
  while (true) {
    if (i > a) {
      ans--;
      break;
    }
    if (i == a) break;
    i *= b;
    ans++;
  }
  return ans;
}
int n, m;
int c[100005];
vector<int> arr[100005];
int dp[100005], parent[100005];
int mark[100005];
bool visited[100005];
int ans = 0;
void dfs(int a, int b) {
  visited[a] = true;
  if (c[a] == 1) {
    if (c[b] == 1)
      dp[a] = 1 + dp[b];
    else
      dp[a] = 1;
  } else {
    dp[a] = 0;
  }
  if (arr[a].size() == 1 && a != 1 && dp[a] <= m) ans++;
  for (int i = 0; i < arr[a].size(); i++) {
    if (!visited[arr[a][i]] && dp[a] <= m) {
      dfs(arr[a][i], a);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    arr[x].push_back(y);
    arr[y].push_back(x);
  }
  memset(dp, 0, sizeof(dp));
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < 100005; i++) visited[i] = false;
  dp[0] = 0;
  dfs(1, 0);
  cout << ans << "\n";
  return 0;
}
