#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
template <typename T1, typename T2>
inline T1 gmax(T1 &a, T2 b) {
  return a = a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 gmin(T1 &a, T2 b) {
  return a = a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
}  // namespace ae86
using ae86::ty;
const int _ = 507, __ = _ + _;
const short snf = 1000;
int to[__], ne[__], he[_] = {0}, ecnt = 1;
long long ev[__];
inline void adde(int a, int b, long long c) {
  to[++ecnt] = b, ev[ecnt] = c, ne[ecnt] = he[a], he[a] = ecnt;
}
inline void addde(int a, int b, long long c) { adde(a, b, c), adde(b, a, c); }
int n, m = 0, val[_];
long long lim;
long long dis[_][_] = {0};
void dfsdis(int rt, int x, int ff) {
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b == ff) continue;
    dis[rt][b] = dis[rt][x] + ev[i], dfsdis(rt, b, x);
  }
}
int dfn[_] = {0}, rdfn[_] = {0}, ndf[_] = {0}, dcnt = 0;
void dfs(int x, int ff) {
  dfn[x] = ++dcnt, rdfn[dcnt] = x;
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b != ff) dfs(b, x);
  }
  ndf[x] = dcnt;
}
int sz[_] = {0};
short f[_][_][_], fs[_][_];
void dfs2(int x, int ff) {
  sz[x] = 1;
  for (int i = 1; i <= n; i++)
    if (i != x && dis[x][i] <= lim) f[x][0][i] = 0;
  f[x][1][x] = val[x] != 1;
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b == ff) continue;
    dfs2(b, x);
    for (int j = 0; j <= min(m, sz[x] + sz[b]); j++)
      for (int k = 1; k <= n; k++) fs[j][k] = snf;
    for (int j = 0; j <= min(m, sz[x]); j++) {
      for (int k = 0; k <= sz[b] && j + k <= m; k++) {
        short v = snf;
        for (int a = dfn[b]; a <= ndf[b]; a++) gmin(v, f[b][k][rdfn[a]]);
        for (int a = 1; a <= n; a++) {
          gmin(fs[j + k][a], f[x][j][a] + f[b][k][a]);
          if (a < dfn[b] || ndf[b] < a)
            gmin(fs[j + k][rdfn[a]], f[x][j][rdfn[a]] + v);
        }
      }
    }
    sz[x] += sz[b];
    for (int j = 0; j <= min(sz[x], m); j++)
      for (int k = 1; k <= n; k++) f[x][j][k] = fs[j][k];
  }
}
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  n = ty(), lim = ty();
  for (int i = 1; i <= n; i++) val[i] = ty(), m += val[i];
  for (int i = 1, a, b, c; i < n; i++)
    a = ty(), b = ty(), c = ty(), addde(a, b, c);
  for (int i = 1; i <= n; i++) dfsdis(i, i, 0);
  memset(f, 63, sizeof(f));
  dfs(1, 0), dfs2(1, 0);
  short ans = snf;
  for (int i = 1; i <= n; i++) gmin(ans, f[1][m][i]);
  if (ans >= snf) ans = -1;
  cout << ans << lf;
  return 0;
}
