#include <bits/stdc++.h>
int getint() {
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  int x = ch ^ '0';
  while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
  return x;
}
template <typename _T1, typename _T2>
_T1 min(const _T1 &a, const _T2 &b) {
  return a < b ? a : b;
}
template <typename _T1, typename _T2>
_T1 max(const _T1 &a, const _T2 &b) {
  return a > b ? a : b;
}
const unsigned short inf = ~0;
const unsigned short N = 501;
bool col[N];
unsigned short n, s;
int m;
int dis[N][N];
std::vector<unsigned short> e[N];
inline void add_edge(const unsigned short &u, const unsigned short &v,
                     const int &w) {
  e[u].push_back(v);
  e[v].push_back(u);
  dis[u][v] = dis[v][u] = w;
}
unsigned short f[N][N][N], best[N][N], size[N];
void dfs(const unsigned short &x, const unsigned short &par) {
  for (unsigned short i = 0; i < e[x].size(); i++) {
    const unsigned short &y = e[x][i];
    if (y == par) continue;
    dfs(y, x);
  }
  for (unsigned short i = 1; i <= n; i++) {
    if (dis[x][i] > m) continue;
    size[x] = 1;
    f[x][i][1] = !col[i];
    for (unsigned short j = 0; j < e[x].size(); j++) {
      const unsigned short &y = e[x][j];
      if (y == par) continue;
      for (unsigned short k = min(s, size[x] + size[y]);; k--) {
        unsigned short tmp = inf;
        for (unsigned short j = max(k - size[x], 0); j <= min(k, size[y]);
             j++) {
          tmp = min(tmp, f[x][i][k - j] + best[y][j]);
        }
        for (unsigned short j = max(k - size[x], 0) + 1; j <= min(k, size[y]);
             j++) {
          tmp = min(tmp, f[x][i][k - j + 1] + f[y][i][j] - !col[i]);
        }
        f[x][i][k] = tmp;
        if (!k) break;
      }
      size[x] += size[y];
    }
  }
  for (unsigned short i = 1; i <= s; i++) {
    best[x][i] = inf;
    for (unsigned short j = 1; j <= n; j++) {
      best[x][i] = min(best[x][i], f[x][j][i]);
    }
  }
}
int main() {
  n = getint(), m = getint();
  for (unsigned short i = 1; i <= n; i++) {
    s += (col[i] = getint());
  }
  memset(dis, 0x3f, sizeof dis);
  for (unsigned short i = 1; i < n; i++) {
    const unsigned short u = getint(), v = getint();
    const int w = getint();
    add_edge(u, v, w);
  }
  for (unsigned short k = 1; k <= n; k++) {
    for (unsigned short i = 1; i <= n; i++) {
      for (unsigned short j = 1; j <= n; j++) {
        dis[i][j] = i == j ? 0 : min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  memset(f, 0xff, sizeof f);
  memset(best, 0xff, sizeof best);
  dfs(1, 0);
  printf("%d\n", best[1][s] == inf ? -1 : best[1][s]);
  return 0;
}
