#include <bits/stdc++.h>
using namespace std;
const int maxn = 505, mod = 998244353;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 0;
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, m, x, c[maxn], el, head[maxn], to[maxn * 2], nxt[maxn * 2], w[maxn * 2],
    sz[maxn], dfn[maxn], cnt, cur, dep[maxn], p[maxn], pre[maxn],
    f[2][maxn][maxn * 2], tmp[maxn][maxn], mn[maxn][maxn];
bool cl[maxn][maxn];
inline void add(int u, int v, int ww) {
  to[++el] = v;
  nxt[el] = head[u];
  head[u] = el;
  w[el] = ww;
}
void dfs(int u, int F) {
  dfn[u] = ++cnt;
  dep[u] = dep[F] + 1;
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == F) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
void dfs2(int u, int F, int rt, int d) {
  if (d > x) return;
  cl[rt][u] = true;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == F) continue;
    dfs2(v, u, rt, d + w[i]);
  }
}
inline bool in(int u, int v) {
  return dfn[v] >= dfn[u] && dfn[v] <= dfn[u] + sz[u] - 1;
}
inline bool cmp(int x, int y) { return dep[x] > dep[y]; }
inline int &g(int cur, int u, int v, int i) { return f[cur][v][i + pre[u]]; }
int main() {
  n = read();
  x = read();
  for (int i = (1); i <= (n); i++) m += c[i] = read();
  for (int i = (1); i <= (n - 1); i++) {
    int u = read(), v = read(), w = read();
    add(u, v, w);
    add(v, u, w);
  }
  dfs(1, 0);
  for (int i = (1); i <= (n); i++) dfs2(i, 0, i, 0);
  for (int i = (1); i <= (n); i++) p[i] = i;
  sort(p + 1, p + n + 1, cmp);
  memset(mn, 0x3f, sizeof(mn));
  for (int i = (1); i <= (n); i++) {
    int j = i;
    while (j < n && dep[p[i]] == dep[p[j + 1]]) j++;
    memset(f[cur], 0x3f, sizeof(f[cur]));
    for (int k = (i); k <= (j); k++) {
      int u = p[k];
      if (k != i) pre[u] = pre[p[k - 1]] + sz[p[k - 1]] + 1;
      g(cur, u, u, 1) = 1 - c[u];
      for (int v = (1); v <= (n); v++)
        if (cl[u][v] && u != v) g(cur, u, v, 0) = 0;
      int s = 1;
      for (int e = head[u]; e; e = nxt[e]) {
        int v = to[e];
        if (dep[v] < dep[u]) continue;
        for (int a = (1); a <= (n); a++)
          for (int x = (0); x <= (s + sz[v]); x++) tmp[a][x] = 1e9;
        for (int a = (1); a <= (n); a++)
          for (int x = (0); x <= (s); x++)
            for (int y = (0); y <= (sz[v]); y++) {
              tmp[a][x + y] =
                  min(tmp[a][x + y], g(cur, u, a, x) + g(cur ^ 1, v, a, y));
              if (!in(v, a))
                tmp[a][x + y] = min(tmp[a][x + y], g(cur, u, a, x) + mn[v][y]);
            }
        s += sz[v];
        for (int a = (1); a <= (n); a++)
          for (int x = (0); x <= (s); x++) g(cur, u, a, x) = tmp[a][x];
        for (int a = (1); a <= (n); a++)
          for (int x = (0); x <= (s); x++) {
          }
      }
      for (int a = (1); a <= (n); a++)
        for (int x = (0); x <= (s); x++) {
          if (in(u, a)) mn[u][x] = min(mn[u][x], g(cur, u, a, x));
        }
    }
    cur ^= 1;
    i = j;
  }
  printf("%d\n", mn[1][m] >= 1e9 ? -1 : mn[1][m]);
}
