#include <bits/stdc++.h>
using namespace std;
long long n, cost[100009], dist[100009];
bool vis[100009];
vector<int> adj[100009];
vector<int> roots;
int cats, check;
int num[100009];
void bfs() {
  queue<int> q;
  int x;
  q.push(1);
  vis[1] = true;
  dist[1] = 0;
  num[1] = cost[1];
  while (!q.empty()) {
    x = q.front();
    q.pop();
    bool yesRoot = true;
    for (int i = 0; i < adj[x].size(); i++) {
      int p = adj[x][i];
      if (!vis[p]) {
        yesRoot = false;
        q.push(p);
        vis[p] = true;
        dist[p] = x;
        if (num[x] == -1)
          num[p] = -1;
        else if (cost[p] > 0 && cost[x] > 0) {
          num[p] = num[x] + cost[p];
          if (num[p] > cats) num[p] = -1;
        } else
          num[p] = cost[p];
      }
    }
    if (yesRoot) roots.push_back(x);
  }
}
int main() {
  long long int m;
  long long x, y, w;
  cin >> n >> cats;
  for (int i = 1; i <= n; i++) cin >> cost[i];
  for (long long int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[y].push_back(x);
    adj[x].push_back(y);
  }
  bfs();
  int check = cats, ans = 0;
  bool flag = true;
  for (int i = 0; i < roots.size(); i++) {
    int x = roots[i];
    if (num[x] != -1) ans++;
  }
  cout << ans << endl;
}
