#include <bits/stdc++.h>
using namespace std;
const int N = 501;
const unsigned inf = 0x3f3f;
int n, m, E, tot;
long long dis[N][N];
int siz[N], col[N], fir[N], nex[N << 1], arr[N << 1];
unsigned short best[N][N], g[N][N], f[N][N][N];
inline void Add_Edge(int x, int y, int l) {
  nex[++E] = fir[x];
  fir[x] = E;
  arr[E] = y;
  dis[x][y] = l;
}
inline void upd(unsigned short &x, unsigned short y) { x = min(x, y); }
void dfs(int x, int fa) {
  siz[x] = 1;
  for (int i = 1; i <= n; ++i) {
    if (dis[x][i] <= m) {
      f[x][i][1] = !col[i];
    }
  }
  for (int i = fir[x]; i; i = nex[i]) {
    int y = arr[i];
    if (y == fa) continue;
    dfs(y, x);
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= siz[x] + siz[y]; ++k) {
        g[j][k] = inf;
      }
    }
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= siz[x]; ++k) {
        for (int l = 1; l <= siz[y]; ++l) {
          upd(g[j][k + l], f[x][j][k] + best[y][l]);
          upd(g[j][k + l - 1], f[x][j][k] + f[y][j][l] - !col[j]);
        }
      }
    }
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= siz[x] + siz[y]; ++k) {
        f[x][j][k] = g[j][k];
      }
    }
    siz[x] += siz[y];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= siz[x]; ++j) {
      upd(best[x][j], f[x][i][j]);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &col[i]);
    tot += col[i];
  }
  memset(dis, 0x3f, sizeof dis);
  for (int i = 1; i <= n; ++i) {
    dis[i][i] = 0;
  }
  for (int i = 1; i < n; ++i) {
    int x, y, l;
    scanf("%d%d%d", &x, &y, &l);
    Add_Edge(x, y, l);
    Add_Edge(y, x, l);
  }
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  memset(f, 0x3f, sizeof f);
  memset(best, 0x3f, sizeof best);
  dfs(1, 0);
  printf("%d\n", best[1][tot] > n ? -1 : best[1][tot]);
  return 0;
}
