#include <bits/stdc++.h>
int c[501], s[501], t[501], n, m, x, ans = 1e3;
short dp[501][501][501], pre[502], suf[502];
int to[1001], dis[1001], nxt[1001], fst[501], tot;
void add(int u, int v, int w) {
  to[++tot] = v, dis[tot] = w;
  nxt[tot] = fst[u], fst[u] = tot;
}
void init(int s, int u, int d, int f) {
  if (d > x) dp[s][0][u] = 1e3;
  for (int e = fst[u]; e; e = nxt[e])
    if (to[e] != f) init(s, to[e], std::min(1000000001, d + dis[e]), u);
}
void dfs(int u, int f) {
  s[u] = 1;
  for (int i = 1; i <= n; ++i)
    for (int p = 1; p <= n; ++p) dp[u][i][p] = 1e3;
  for (int e = fst[u], v; e; e = nxt[e])
    if ((v = to[e]) != f) {
      dfs(v, u);
      for (int i = s[u] + s[v] - 1; i >= 0; --i) {
        for (int p = 1; p <= n; ++p) t[p] = 1e3;
        for (int j = std::max(0, i - s[v]); j <= std::min(s[u] - 1, i); ++j) {
          for (int p = 1; p <= n; ++p)
            if (i - j)
              pre[p] =
                  std::min(pre[p - 1], (short)(dp[v][i - j - 1][p] + !c[p]));
            else
              pre[p] = pre[p - 1];
          for (int p = n; p >= 1; --p)
            if (i - j)
              suf[p] =
                  std::min(suf[p + 1], (short)(dp[v][i - j - 1][p] + !c[p]));
            else
              suf[p] = suf[p + 1];
          for (int p = 1; p <= n; ++p)
            t[p] = std::min(
                t[p], dp[u][j][p] + std::min(std::min(pre[p - 1], suf[p + 1]),
                                             dp[v][i - j][p]));
        }
        for (int p = 1; p <= n; ++p) dp[u][i][p] = t[p];
      }
      s[u] += s[v];
    }
}
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]), m += c[i];
  for (int i = 1, u, v, w; i < n; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w), add(v, u, w);
  }
  for (int i = 1; i <= n; ++i) init(i, i, 0, 0);
  pre[0] = suf[n + 1] = 1e3, dfs(1, 0);
  for (int i = 1; i <= n; ++i) ans = std::min(ans, dp[1][m - 1][i] + !c[i]);
  printf("%d\n", ans > s[1] ? -1 : ans);
  return 0;
}
