#include <bits/stdc++.h>
using namespace std;
int n, X;
short f[505][505][505], v[505][505], g[505], tg[505], b[505];
int s[505];
long long d[505][505];
int tot;
int a[505 * 2], h[505 * 2], e[505 * 2];
int sum;
void add(int x, int y) {
  a[++tot] = y;
  e[tot] = h[x];
  h[x] = tot;
}
void dfs(int k, int fa) {
  for (int go = h[k]; go; go = e[go]) {
    int u = a[go];
    if (u == fa) continue;
    dfs(u, k);
  }
  for (int x = 0; x < n; ++x) {
    if (X < d[k][x]) continue;
    g[1] = b[x];
    for (int i = 2; i <= n; ++i) {
      g[i] = 2570;
    }
    s[k] = 1;
    for (int go = h[k]; go; go = e[go]) {
      int u = a[go];
      if (u == fa) continue;
      for (int c = 1; c <= n; ++c) {
        tg[c] = 2570;
      }
      for (int c = 1; c <= s[u]; ++c) {
        for (int p = 1; p <= s[k]; ++p) {
          tg[p + c] = min((int)tg[p + c], g[p] + v[u][c]);
          tg[p + c - 1] = min((int)tg[p + c - 1], g[p] + f[u][x][c] - b[x]);
        }
      }
      s[k] += s[u];
      for (int c = 1; c <= n; ++c) {
        g[c] = tg[c];
      }
    }
    for (int j = 1; j <= s[k]; ++j) {
      f[k][x][j] = g[j];
      v[k][j] = min(v[k][j], g[j]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &X);
  sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    sum += b[i];
    b[i] = 1 - b[i];
  }
  int x, y, z;
  memset(d, 10, sizeof(d));
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    --x;
    --y;
    add(x, y);
    add(y, x);
    d[x][y] = d[y][x] = z;
  }
  for (int i = 0; i < n; ++i) {
    d[i][i] = 0;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  memset(v, 10, sizeof(v));
  memset(f, 10, sizeof(f));
  dfs(0, -1);
  short ans = 2570;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= sum; ++j) {
      ans = min(ans, f[0][i][j]);
    }
  }
  if (ans == 2570) ans = -1;
  printf("%d\n", ans);
  return 0;
}
