#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, dis;
  Edge() {}
  Edge(int v, int dis) : v(v), dis(dis) {}
};
vector<Edge> adj[510];
short dp[510][510][510], ans[510][510];
int nBlack;
int father[510], n, x, col[510], dis[510][510], size[510];
void update(short &a, short b) {
  if (a > b) a = b;
}
void BFS(int st) {
  static int queue[510];
  static bool use[510];
  memset(use, false, sizeof(use));
  int front = 0, rear = 1;
  queue[rear] = st, use[st] = true;
  while (front < rear) {
    int p = queue[++front];
    for (__typeof(adj[p].begin()) i = adj[p].begin(); i != adj[p].end(); ++i)
      if (use[i->v] == false) {
        queue[++rear] = i->v;
        use[i->v] = true;
        dis[st][i->v] = min(dis[st][p] + i->dis, x + 1);
      }
  }
}
void read() {
  scanf("%d %d", &n, &x);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", col + i);
    nBlack += col[i];
    col[i] ^= 1;
  }
  for (int i = 2, a, b, c; i <= n; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    adj[a].push_back(Edge(b, c));
    adj[b].push_back(Edge(a, c));
  }
  for (int i = 1; i <= n; ++i) BFS(i);
}
void DFS(int p) {
  static short tmp[510][510], son[510];
  size[p] = 1;
  for (__typeof(adj[p].begin()) i = adj[p].begin(); i != adj[p].end(); ++i)
    if (i->v != father[p]) {
      father[i->v] = p;
      DFS(i->v);
      size[p] += size[i->v];
    }
  for (int w = 1; w <= n; ++w) {
    for (int j = 0; j <= nBlack; ++j) dp[p][j][w] = 10000;
    if (dis[w][p] > x) continue;
    int nSon = 0;
    for (__typeof(adj[p].begin()) i = adj[p].begin(); i != adj[p].end(); ++i)
      if (i->v != father[p]) son[++nSon] = i->v;
    for (int i = 1, tot = 0; i <= nSon; ++i) {
      for (int j = 0; j <= nBlack; ++j) tmp[i][j] = 10000;
      int c = son[i];
      for (int j = 0; j <= tot && j <= nBlack; ++j)
        for (int k = 0; k <= size[c] && k + j <= nBlack; ++k) {
          update(tmp[i][j + k], tmp[i - 1][j] + dp[c][k][w]);
          update(tmp[i][j + k], tmp[i - 1][j] + ans[c][k]);
        }
      tot += size[c];
    }
    for (int i = 0; i <= size[p]; ++i) dp[p][i][w] = tmp[nSon][i];
  }
  ans[p][0] = 10000;
  for (int i = 0; i < size[p]; ++i) {
    ans[p][i + 1] = 10000;
    for (int w = 1; w <= n; ++w) update(ans[p][i + 1], dp[p][i][w] + col[w]);
  }
}
void print() {
  short sum = *min_element(ans[1], ans[1] + nBlack + 1);
  if (sum == 10000)
    printf("-1\n");
  else
    printf("%d\n", sum);
}
int main() {
  read();
  DFS(1);
  print();
  return 0;
}
