#include <bits/stdc++.h>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class Ta, class Tb>
void cxk(Ta& a, Tb b) {
  a = a > b ? a : b;
}
template <class Ta, class Tb>
void cnk(Ta& a, Tb b) {
  a = a < b ? a : b;
}
int n, D, fir[510], dis[1010], nxt[1010], w[1010], id, siz[510],
    isson[510][510];
short f[510][510][510], nf[510][510];
void link(int a, int b, int c) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;
}
int gt[510], col[510];
void DFS(int x, int from, int d, int e, int fa = -1) {
  if (d < 0) return;
  isson[from][x] = e;
  f[from][x][from == x] = ((from == x) ^ (col[from]));
  for (int i = fir[x]; i; i = nxt[i]) {
    if (fa == dis[i]) continue;
    DFS(dis[i], from, d - w[i], e, x);
  }
}
void dfs(int x, int fa = -1, int faw = 0) {
  if (~fa) DFS(fa, x, D - faw, 0, x);
  DFS(x, x, D, 1, fa);
  siz[x] = 1;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (dis[i] == fa) continue;
    dfs(dis[i], x, w[i]);
    memset(gt, 63, sizeof gt);
    for (int y = 1; y <= n; ++y)
      if (isson[dis[i]][y])
        for (int j = 0; j <= n; ++j) cnk(gt[j], (int)f[dis[i]][y][j]);
    memset(nf, 63, sizeof nf);
    for (int y = 1; y <= n; ++y)
      if (isson[dis[i]][y]) {
        for (int sx = 0; sx <= siz[x]; ++sx)
          for (int sy = 0; sy <= siz[dis[i]]; ++sy)
            cnk(nf[y][sx + sy], f[x][y][sx] + f[dis[i]][y][sy]);
      } else {
        for (int sx = 0; sx <= siz[x]; ++sx)
          for (int sy = 0; sy <= siz[dis[i]]; ++sy)
            cnk(nf[y][sx + sy], f[x][y][sx] + gt[sy]);
        for (int sx = 0; sx <= siz[x]; ++sx)
          for (int sy = 0; sy <= siz[dis[i]]; ++sy)
            cnk(nf[y][sx + sy], f[x][y][sx] + f[dis[i]][y][sy]);
      }
    siz[x] += siz[dis[i]];
    memcpy(f[x], nf, sizeof nf);
  }
}
int main() {
  memset(f, 63, sizeof f);
  n = gi(), D = gi();
  int sc = 0;
  memset(f, 63, sizeof f);
  for (int i = 1; i <= n; ++i) col[i] = gi(), sc += col[i];
  int u, v, w;
  for (int i = 1; i < n; ++i)
    u = gi(), v = gi(), w = gi(), link(u, v, w), link(v, u, w);
  dfs(1);
  int ans = 1e9;
  for (int i = 1; i <= n; ++i) cnk(ans, (int)f[1][i][sc]);
  if (ans > n) ans = -2;
  printf("%d\n", ans / 2);
  return 0;
}
