#include <bits/stdc++.h>
using namespace std;
struct pat {
  int x, y;
  pat(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator<(const pat &p) const { return x == p.x ? y < p.y : x < p.x; }
};
template <typename TP>
inline void read(TP &tar) {
  TP ret = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ret = ret * 10 + (ch - '0');
    ch = getchar();
  }
  tar = ret * f;
}
template <typename TP, typename... Args>
inline void read(TP &t, Args &...args) {
  read(t), read(args...);
}
namespace RKK {
const int N = 511;
const double eps = 1e-8, inf = 1e18;
int cz(const double &a) { return fabs(a) <= eps ? 0 : (a > eps ? 1 : -1); }
struct sumireko {
  int to, ne, w;
} e[N << 1];
int he[N], ecnt;
void addline(int f, int t, int w) {
  e[++ecnt].to = t, e[ecnt].w = w, e[ecnt].ne = he[f], he[f] = ecnt;
}
namespace lisp {
int n, m, id[N << 1];
double a[N][N];
void pivot(int l, int e) {
  swap(id[m + l], id[e]);
  double k = -a[l][e];
  a[l][e] = -1;
  for (int j = 0; j <= m; j++) a[l][j] /= k;
  for (int i = 0; i <= n; i++)
    if (i != l && cz(a[i][e])) {
      k = a[i][e], a[i][e] = 0;
      for (int j = 0; j <= m; j++) a[i][j] += k * a[l][j];
    }
}
int init() {
  for (int i = 1; i <= m + n; i++) id[i] = i;
  while (1) {
    int l = 0, e = 0;
    for (int i = 1; i <= n; i++)
      if (cz(a[i][0]) < 0 && (!l || rand() & 1)) l = i;
    if (!l) break;
    for (int j = 1; j <= m; j++)
      if (cz(a[l][j]) > 0 && (!e || rand() & 1)) e = j;
    if (!e) return -1;
    pivot(l, e);
  }
  return 0;
}
int simplex() {
  while (1) {
    int l = 0, e = 0;
    double mi = inf;
    for (int j = 1; j <= m; j++)
      if (cz(a[0][j]) > 0 && (!e || rand() & 1)) e = j;
    if (!e) break;
    for (int i = 1; i <= n; i++)
      if (cz(a[i][e]) < 0 && (!l || -a[i][0] / a[i][e] < mi))
        l = i, mi = -a[i][0] / a[i][e];
    if (!l) return -1;
    pivot(l, e);
  }
  return 0;
}
void work() {
  if (init() == -1) return (void)(puts("-1"));
  if (simplex() == -1) return (void)(puts("-1"));
  printf("%.0lf\n", a[0][0]);
}
}  // namespace lisp
int n, m, lim, col[N];
void dfs(int x, int f, int sp, int dis) {
  if (dis > lim) return;
  lisp::a[x][sp] = -1;
  for (int i = he[x], t = e[i].to; i; i = e[i].ne, t = e[i].to)
    if (t != f) dfs(t, x, sp, dis + e[i].w);
}
int main() {
  read(n, lim);
  for (int i = 1; i <= n; i++) read(col[i]), m += col[i];
  for (int i = 2, x, y, w; i <= n; i++)
    read(x, y, w), addline(x, y, w), addline(y, x, w);
  lisp::n = n, lisp::m = n + 2;
  for (int i = 1; i <= n; i++) lisp::a[i][0] = !col[i], lisp::a[0][i] = 1;
  lisp::a[0][n + 1] = m, lisp::a[0][n + 2] = -m;
  for (int i = 1; i <= n; i++) lisp::a[i][n + 1] = -1, lisp::a[i][n + 2] = 1;
  for (int i = 1; i <= n; i++) dfs(i, 0, i, 0);
  lisp::work();
  return 0;
}
}  // namespace RKK
int main() { return RKK::main(); }
