#include <bits/stdc++.h>
using namespace std;
const int maxn = 503;
const short inf = 0x3f3f;
int read() {
  char c;
  int x = 0, flag = 1;
  while ((c = getchar()) && (c < '0' || c > '9'))
    if (c == '-') flag = -1;
  do x = x * 10 + c - '0';
  while ((c = getchar()) && c >= '0' && c <= '9');
  return x * flag;
}
int n, x, a[maxn], dfnst[maxn], head[maxn], cnt;
int dfnen[maxn], tra[maxn], clo, sz[maxn], sum;
short f[maxn][maxn][maxn], g[maxn][maxn], tmp[maxn];
long long dis[maxn][maxn], d[maxn];
struct edge {
  int next, to, w;
} seg[maxn << 1];
void add_seg(int u, int v, int w) {
  seg[++cnt] = (edge){head[u], v, w};
  head[u] = cnt;
  seg[++cnt] = (edge){head[v], u, w};
  head[v] = cnt;
}
void dfs(int cur, int pre) {
  tra[dfnst[cur] = ++clo] = cur;
  for (int i = head[cur]; i != 0; i = seg[i].next)
    if (seg[i].to != pre) {
      d[seg[i].to] = d[cur] + (long long)seg[i].w;
      dfs(seg[i].to, cur);
    }
  dfnen[cur] = clo;
  for (int i = head[cur]; i != 0; i = seg[i].next)
    for (int j = seg[i].next; j != 0; j = seg[j].next)
      for (int k = dfnst[seg[i].to]; k <= dfnen[seg[i].to]; k++)
        for (int l = dfnst[seg[j].to]; l <= dfnen[seg[j].to]; l++)
          dis[tra[k]][tra[l]] = dis[tra[l]][tra[k]] =
              d[tra[k]] + d[tra[l]] - d[cur] * 2;
  for (int i = dfnst[cur]; i <= dfnen[cur]; i++)
    dis[tra[i]][cur] = dis[cur][tra[i]] = d[tra[i]] - d[cur];
}
void calc(int cur, int pre) {
  for (int i = head[cur]; i != 0; i = seg[i].next)
    if (seg[i].to != pre) {
      calc(seg[i].to, cur);
      for (int p = 1; p <= n; p++)
        if (dis[cur][p] <= x) {
          for (int j = 0; j <= sz[cur] + sz[seg[i].to]; j++) tmp[j] = inf;
          for (int j = 0; j <= sz[cur]; j++)
            for (int k = 0; k <= sz[seg[i].to]; k++)
              tmp[j + k] =
                  min(tmp[j + k], (short)(f[cur][p][j] + min(f[seg[i].to][p][k],
                                                             g[seg[i].to][k])));
          for (int j = 0; j <= sz[cur] + sz[seg[i].to]; j++)
            f[cur][p][j] = tmp[j];
        }
      sz[cur] += sz[seg[i].to];
    }
  sz[cur]++;
  memset(g[cur], 0x3f, sizeof g[cur]);
  for (int p = 1; p <= n; p++) {
    f[cur][p][sz[cur]] = inf;
    if (dis[cur][p] > x) {
      for (int j = 0; j < sz[cur]; j++) f[cur][p][j] = inf;
      continue;
    }
    for (int j = 0; j < sz[cur]; j++)
      g[cur][j + 1] = min(g[cur][j + 1], (short)(f[cur][p][j] + (a[p] == 0)));
  }
}
int main() {
  n = read(), x = read();
  for (int i = 1; i <= n; i++) sum += (a[i] = read());
  for (int i = 1; i < n; i++) {
    int u = read(), v = read(), w = read();
    add_seg(u, v, w);
  }
  dfs(1, 0);
  calc(1, 0);
  short ans = inf;
  for (int i = 1; i <= sum; i++) ans = min(ans, g[1][i]);
  printf("%d\n", ans == inf ? -1 : ans);
  return 0;
}
