#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, X, tot, S, sz[N];
int head[N], a[N];
long long d[N][N];
short tmp[N];
short ff[N][N];
short f[N][N][N];
struct edge {
  int to, next;
} e[N * 2];
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) dfs(e[i].to, x);
  for (int i = (int)(1); i <= (int)(n); i++)
    if (d[x][i] <= X) {
      sz[x] = 1;
      f[x][i][1] = 1 - a[i];
      for (int j = head[x]; j; j = e[j].next)
        if (e[j].to != fa) {
          int y = e[j].to;
          for (int k = (int)(0); k <= (int)(sz[x] + sz[y]); k++) tmp[k] = 10000;
          for (int k = (int)(0); k <= (int)(sz[x]); k++)
            for (int l = (int)(0); l <= (int)(sz[y]); l++) {
              tmp[k + l] = min(tmp[k + l], (short)(f[x][i][k] + ff[y][l]));
              tmp[k + l] = min(tmp[k + l], (short)(f[x][i][k] + f[y][i][l + 1] -
                                                   (1 - a[i])));
            }
          sz[x] += sz[y];
          for (int k = (int)(0); k <= (int)(sz[x]); k++) f[x][i][k] = tmp[k];
        }
      for (int j = (int)(0); j <= (int)(sz[x]); j++) {
        ff[x][j] = min(ff[x][j], f[x][i][j]);
      }
    }
}
int main() {
  scanf("%d%d", &n, &X);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) S += a[i];
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      d[i][j] = (i == j ? 0 : 1ll << 60);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    add(x, y);
    add(y, x);
    d[x][y] = d[y][x] = v;
  }
  for (int k = (int)(1); k <= (int)(n); k++)
    for (int i = (int)(1); i <= (int)(n); i++)
      for (int j = (int)(1); j <= (int)(n); j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  memset(f, 30, sizeof(f));
  memset(ff, 30, sizeof(ff));
  dfs(1, 0);
  short ans = 23333;
  for (int i = (int)(1); i <= (int)(S); i++) ans = min(ans, ff[1][i]);
  printf("%d\n", ans > 1000 ? -1 : ans);
}
