import java.util.*
fun main(args:Array<String>?): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val nodes = Array(n){Stack<Edge>()}
    repeat(n - 1){
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        nodes[a - 1].add(Edge(b - 1, c))
        nodes[b - 1].add(Edge(a - 1, c))
    }
    val servers = readLine()!!.trim().split(' ').map(String::toLong).toLongArray()
    println(solve(servers, nodes).let{
        list -> list.take(Math.min(list.size, m)).fold(0L){a, b -> a + b}
    })
}
data class Edge(val to: Int, val distance: Int)
fun solve(servers: LongArray, nodes: Array<out Collection<Edge>>): LongArray {
    val parents = IntArray(nodes.size){-1}
    val cache = Array(nodes.size){ listOf<Int>()}
    fun sub(current: Int, prev: Int): List<Int> {
        return if (parents[current] == prev) cache[current]
        else {
            parents[current] = prev
            cache[current] = nodes[current].filterNot{it.to == prev}.flatMap{(to, distance) ->
                val res = sub(to, current)
                if (res.isEmpty()) listOf(distance)
                else listOf(res.drop(1), listOf(res.first() + distance)).flatten()
            }.sortedDescending()
            cache[current]
        }
    }
    val results = MutableList(servers.size){listOf<Long>()}
    fun dfs(current: Int, prev: Int = -1): Unit {
        results[current] = sub(current, nodes.size).map{it * servers[current]}
        nodes[current].forEach{
            if (it.to != prev) dfs(it.to, current)
        }
    }
    dfs(0)
    return results.flatten().sortedDescending().toLongArray()
}
