#include <bits/stdc++.h>
inline int read() {
  int data = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
  return data * w;
}
const int N(505);
struct edge {
  int next, to, dis;
} e[N << 1];
int n, m, X, head[N], e_num, c[N], dis[N][N], vis[N], L[N], R[N], cnt, pos[N],
    size[N];
short f[N][N][N], g[N][N];
inline void add_edge(int from, int to, int dis) {
  e[++e_num] = (edge){head[from], to, dis}, head[from] = e_num;
}
void bfs(int S) {
  std::queue<int> Q;
  Q.push(S), std::memset(vis + 1, 0, n << 2);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop(), vis[x] = 1;
    for (int i = head[x]; i; i = e[i].next) {
      int to = e[i].to;
      if (vis[to]) continue;
      dis[S][to] = dis[S][x] + e[i].dis, Q.push(to);
    }
  }
}
void dfs(int x, int fa) {
  pos[L[x] = ++cnt] = x;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) dfs(e[i].to, x);
  R[x] = cnt;
}
void dp(int x, int fa) {
  for (int i = 1; i <= n; i++)
    if (i != x && dis[x][i] <= X) f[x][0][i] = 0;
  f[x][1][x] = c[x] ^ 1, size[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int to = e[i].to;
    if (to == fa) continue;
    dp(to, x);
    for (int j = 0; j <= std::min(size[x] + size[to], m); j++)
      for (int k = 1; k <= n; k++) g[j][k] = n + 1;
    for (int j = 0; j <= std::min(size[x], m); j++)
      for (int k = 0; k <= std::min(size[to], m); k++) {
        short v = n + 1;
        for (int y = L[to]; y <= R[to]; y++)
          v = std::min<short>(v, f[to][k][pos[y]]);
        for (int y = 1; y <= n; y++)
          g[j + k][y] = std::min<short>(g[j + k][y], f[x][j][y] + f[to][k][y]);
        for (int y = 1; y < L[to]; y++)
          g[j + k][pos[y]] =
              std::min<short>(g[j + k][pos[y]], f[x][j][pos[y]] + v);
        for (int y = R[to] + 1; y <= n; y++)
          g[j + k][pos[y]] =
              std::min<short>(g[j + k][pos[y]], f[x][j][pos[y]] + v);
      }
    size[x] += size[to];
    for (int j = 0; j <= std::min(size[x], m); j++)
      for (int k = 1; k <= n; k++) f[x][j][k] = g[j][k];
  }
}
int main() {
  n = read(), X = read();
  for (int i = 1; i <= n; i++) m += (c[i] = read());
  for (int i = 1, a, b, c; i < n; i++)
    a = read(), b = read(), c = read(), add_edge(a, b, c), add_edge(b, a, c);
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 1; k <= n; k++) f[i][j][k] = n + 1;
  dfs(1, 0), dp(1, 0);
  short ans = n + 1;
  for (int i = 1; i <= n; i++) ans = std::min(ans, f[1][m][i]);
  printf("%d\n", ans > n ? -1 : ans);
  return 0;
}
