#include <bits/stdc++.h>
using namespace std;
int n, m, V, i, x, y, z, tot, e[505], fir[505], ne[505 * 2], la[505 * 2],
    va[505 * 2];
double v, o, a[505][505], b[505], c[505];
void ins(int x, int y, int z) {
  la[++tot] = y;
  ne[tot] = fir[x];
  fir[x] = tot;
  va[tot] = z;
}
void dfs(int A, int x, int fa, long long z) {
  if (z <= V) a[x][A] = 1;
  for (int i = fir[x]; i; i = ne[i])
    if (la[i] != fa) dfs(A, la[i], x, z + va[i]);
}
void pivot(int l, int e) {
  int i, j;
  for (a[l][e] = 1 / a[l][e], b[l] *= a[l][e], i = 1; i <= n; i++)
    if (i != e) a[l][i] *= a[l][e];
  for (i = 1; i <= m; i++)
    if (i != l && fabs(a[i][e]) > 1e-7) {
      for (b[i] -= a[i][e] * b[l], j = 1; j <= n; j++)
        if (j != e) a[i][j] -= a[i][e] * a[l][j];
      a[i][e] *= -a[l][e];
    }
  for (v += c[e] * b[l], i = 1; i <= n; i++)
    if (i != e) c[i] -= c[e] * a[l][i];
  c[e] *= -a[l][e];
}
double simplex() {
  for (int i, j, e, l; 1;) {
    for (i = 1; i <= n; i++)
      if (c[i] > 1e-7) break;
    if ((e = i) == n + 1) return v;
    double tmp = 1e99;
    for (i = 1; i <= m; i++)
      if (a[i][e] > 1e-7 && tmp > b[i] / a[i][e]) tmp = b[i] / a[i][e], l = i;
    if (tmp == 1e99) break;
    pivot(l, e);
  }
  return 1e99;
}
int main() {
  for (scanf("%d%d", &n, &V), i = 1; i <= n; i++)
    scanf("%d", &e[i]), b[i] = !e[i], a[i][n + 1] = 1, a[i][n + 2] = -1,
                        c[n + 1] += e[i], c[n + 2] -= e[i], c[i] = 1;
  for (i = 1; i < n; i++)
    scanf("%d%d%d", &x, &y, &z), ins(x, y, z), ins(y, x, z);
  for (i = 1; i <= n; i++) dfs(i, i, 0, 0);
  m = n;
  n += 2;
  o = simplex();
  if (o == 1e99)
    puts("-1");
  else
    printf("%.0lf", o);
}
