import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  val Array(n, w) = readLine.trim.split(' ').map(_.toInt)
  val price = readLine.trim.split(' ').map(_.toLong)
  val nodes = Array.fill(n){Nil: List[Route]}
  for (_ ← 1 until n){
    val Array(u, v, c) = readLine.trim.split(' ').map(_.toInt)
    nodes(u - 1) ::= Route(v - 1, c)
    nodes(v - 1) ::= Route(u - 1, c)
  }
  val depth = Array.fill(n){Int.MaxValue}; depth(0) = 0
  val stack = mutable.Stack[Int](0)
  val parents = Array.fill(n){0}
  while(stack.nonEmpty){
    val current = stack.pop()
    for (Route(next, _) ← nodes(current) if depth(next) > depth(current)) {
      depth(next) = depth(current) + 1
      parents(next) = current
      stack.push(next)
    }
  }
  val childCount = Array.fill(n){1}
  def count(current: Int): Int = {
    for (Route(next, _) ← nodes(current) if depth(current) < depth(next)) childCount(current) += count(next)
    childCount(current)
  }
  count(0)
  for (i ← nodes.indices) nodes(i) = nodes(i).filter(r ⇒ depth(r.to) > depth(i)).sortBy(r ⇒ childCount(r.to))(Ordering.Int.reverse)
  val array = Array.fill(n){(Array.fill(w + 1){0L}, Array.fill(w + 1){0L}, Array.fill(w + 1){0L})}
  println(search(0, Array.fill(w + 1){0L})._3.max)

  def search(current: Int, state: Array[Long]): (Array[Long], Array[Long], Array[Long]) = {
    val (x, y, z) = array(current)
    nodes(current) match {
      case Route(first, firstCost)::t ⇒
        val (ix, iy, iz) = search(first, state)
        for (i ← (firstCost until ix.length).reverse) {
          x(i) = math.max(state(i), ix(i - firstCost)) + price(current)
          y(i) = iy(i - firstCost) + price(current)
          z(i) = math.max(iz(i), y(i))
        }
        for (i ← 0 until math.min(state.length, firstCost)) {
          x(i) = state(i) + price(current)
          y(i) = price(current)
          z(i) = math.max(iz(i), y(i))
        }
        for (Route (next, cost) ← t) {
          val (ax, _, az) = search(next, x)
          for (i ← z.indices) {
            z(i) = math.max (z(i), az(i))
          }
          for (i ← cost until x.length) {
            x(i) = math.max(x(i), ax(i - cost))
          }
          val (bx, _, _) = search(next, y)
          for (i ← cost until x.length) {
            y(i) = math.max (y(i), bx(i - cost))
          }
        }
        for (i ← z.indices) {
          z(i) = math.max (z(i), y(i))
        }
        (x, y, z)
      case Nil ⇒
        for (i ← x.indices) {
          x(i) = state(i) + price(current)
          y(i) = price(current)
        }
        (x, y, y)
    }
  }
  case class Route(to: Int, cost: Int)
  case class Road(a: Int, b: Int, cost: Long)
  implicit class Scope[T](val value: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(value)
    def also(@inline func: T ⇒ Unit): T = {func(value);value}
  }
}
