#include <bits/stdc++.h>
using namespace std;
unsigned short f[501][501][501];
vector<bool> black;
vector<unsigned> num;
vector<vector<unsigned> > line, best;
vector<vector<unsigned> > dis;
inline void dfs(const unsigned &now, const unsigned &last, const unsigned &n,
                const unsigned &x, const unsigned &s) {
  unsigned i, j, k, l, temp;
  for (i = 0; i < line[now].size(); ++i)
    if (line[now][i] != last) dfs(line[now][i], now, n, x, s);
  for (i = 1; i <= n; ++i) {
    if (dis[now][i] > x) continue;
    num[now] = 1;
    f[now][i][1] = !black[i];
    for (j = 0; j < line[now].size(); ++j)
      if (line[now][j] != last) {
        for (k = min(s, num[now] + num[line[now][j]]); k + 1; --k) {
          temp = n;
          for (l = max(k, num[now]) - num[now]; l <= min(k, num[line[now][j]]);
               ++l) {
            temp =
                min(temp, (unsigned)f[now][i][k - l] + best[line[now][j]][l]);
          }
          for (l = max(k, num[now]) - num[now] + 1;
               l <= min(k, num[line[now][j]]); ++l) {
            temp = min(temp, (unsigned)f[now][i][k - l + 1] +
                                 f[line[now][j]][i][l] - !black[i]);
          }
          f[now][i][k] = temp;
        }
        num[now] += num[line[now][j]];
      }
  }
  for (i = 1; i <= s; ++i)
    for (j = 1; j <= n; ++j) {
      best[now][i] = min(best[now][i], (unsigned)f[now][j][i]);
    }
}
int main(void) {
  unsigned i, j, k, l, n, s = 0, x;
  cin >> n >> x;
  black.resize(n + 1);
  num.resize(n + 1);
  dis.resize(n + 1);
  line.resize(n + 1);
  best.resize(n + 1);
  for (i = 1; i <= n; ++i) {
    cin >> j;
    s += (black[i] = j);
    dis[i].resize(n + 1);
    best[i].resize(n + 1);
    for (j = 0; j <= n; ++j) {
      dis[i][j] = x + 1;
      best[i][j] = n;
      for (k = 0; k <= n; ++k) f[i][j][k] = n;
    }
    dis[i][i] = 0;
  }
  for (i = 1; i < n; ++i) {
    cin >> j >> k >> l;
    line[j].push_back(k);
    line[k].push_back(j);
    dis[j][k] = dis[k][j] = l;
  }
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      for (k = 1; k <= n; ++k)
        dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
  dfs(1, 0, n, x, s);
  if (best[1][s] <= s)
    cout << best[1][s] << endl;
  else
    cout << -1 << endl;
  return 0;
}
