#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k = p - 2) {
  register long long re = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) re = re * x % p;
  return re;
}
int head[505], to[1005], ne[1005], val[1005], total = 1;
inline void add(int a, int b, int c) {
  total++;
  to[total] = b;
  val[total] = c;
  ne[total] = head[a];
  head[a] = total;
}
int n, X;
int col[505];
int in[505], out[505];
int dfn_top;
long long dis[505][505];
void dfs1(int now, int fa) {
  in[now] = ++dfn_top;
  for (int i = head[now]; i; i = ne[i])
    if (to[i] != fa) dfs1(to[i], now);
  out[now] = dfn_top;
}
void dfs2(int now, int fa, int id) {
  for (int i = head[now]; i; i = ne[i])
    if (to[i] != fa) {
      dis[id][to[i]] = dis[id][now] + val[i];
      dfs2(to[i], now, id);
    }
}
short f[505][505][505];
inline bool sub(int x, int y) { return in[x] <= in[y] && in[y] <= out[x]; }
int sz[505];
int cnt;
void dfs(int now, int fa) {
  sz[now] = 1;
  for (int i = 1; i <= n; i++)
    if (i != now && dis[i][now] <= X) f[now][0][i] = 0;
  f[now][1][now] = col[now] ^ 1;
  for (int i = head[now]; i; i = ne[i])
    if (to[i] != fa) {
      dfs(to[i], now);
      int AA = min(sz[now], cnt), BB = min(sz[to[i]], cnt);
      static short g[505][505];
      for (int a = 0; a <= n; a++)
        for (int b = 0; b <= n; b++) g[a][b] = f[now][a][b];
      memset(f[now], 0x3f, sizeof(f[now]));
      for (int A = 0; A <= AA; A++)
        for (int B = 0; B <= BB; B++) {
          for (int a = 1; a <= n; a++)
            f[now][A + B][a] =
                min((int)f[now][A + B][a], g[A][a] + f[to[i]][B][a]);
          short mi = 0x3f3f;
          for (int j = 1; j <= n; j++)
            if (sub(to[i], j)) mi = min(mi, f[to[i]][B][j]);
          for (int j = 1; j <= n; j++)
            if (!sub(to[i], j))
              f[now][A + B][j] = min((int)f[now][A + B][j], mi + g[A][j]);
        }
      sz[now] += sz[to[i]];
    }
}
int main() {
  read(n, X);
  for (int i = 1; i <= n; i++) read(col[i]), cnt += col[i];
  for (int i = 1, x, y, z; i < n; i++)
    read(x, y, z), add(x, y, z), add(y, x, z);
  dfs1(1, 1);
  for (int i = 1; i <= n; i++) dfs2(i, i, i);
  memset(f, 0x3f, sizeof(f));
  dfs(1, 1);
  short ans = 0x3f3f;
  for (int i = 0; i <= cnt; i++)
    for (int j = 1; j <= n; j++) ans = min(ans, f[1][i][j]);
  if (ans == 0x3f3f) return printf("-1"), 0;
  cout << ans;
  return 0;
}
