← Home
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

type Edge struct {
	to     int
	weight int64
}

type Item struct {
	u int
	A int64
}

type MaxHeap []Item

func (h MaxHeap) Len() int           { return len(h) }
func (h MaxHeap) Less(i, j int) bool { return h[i].A > h[j].A }
func (h MaxHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *MaxHeap) Push(x interface{}) {
	*h = append(*h, x.(Item))
}
func (h *MaxHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var scanner *bufio.Scanner

func initScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	const maxCapacity = 10 * 1024 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

func nextInt() int {
	scanner.Scan()
	res := 0
	sign := 1
	for _, b := range scanner.Bytes() {
		if b == '-' {
			sign = -1
		} else {
			res = res*10 + int(b-'0')
		}
	}
	return res * sign
}

func nextInt64() int64 {
	scanner.Scan()
	var res int64 = 0
	var sign int64 = 1
	for _, b := range scanner.Bytes() {
		if b == '-' {
			sign = -1
		} else {
			res = res*10 + int64(b-'0')
		}
	}
	return res * sign
}

func main() {
	initScanner()

	n := nextInt()
	m := nextInt()

	adj := make([][]Edge, n+1)
	for i := 0; i < n-1; i++ {
		u := nextInt()
		v := nextInt()
		w := nextInt64()
		adj[u] = append(adj[u], Edge{v, w})
		adj[v] = append(adj[v], Edge{u, w})
	}

	A := make([]int64, n+1)
	B := make([]int64, n+1)

	bfs := func(start int, dist []int64) {
		for i := range dist {
			dist[i] = -1
		}
		dist[start] = 0
		queue := make([]int, 0, n)
		queue = append(queue, start)
		for len(queue) > 0 {
			u := queue[0]
			queue = queue[1:]
			for _, edge := range adj[u] {
				v := edge.to
				if dist[v] == -1 {
					dist[v] = dist[u] + edge.weight
					queue = append(queue, v)
				}
			}
		}
	}

	bfs(1, A)
	bfs(n, B)

	D := A[n]

	type Node struct {
		id int
		C  int64
	}
	nodes := make([]Node, 0, n)
	for i := 1; i <= n; i++ {
		nodes = append(nodes, Node{id: i, C: A[i] - B[i]})
	}

	sort.Slice(nodes, func(i, j int) bool {
		return nodes[i].C < nodes[j].C
	})

	isNeighbor := make([]bool, n+1)
	h := &MaxHeap{}
	heap.Init(h)

	var M int64 = 0

	for _, node := range nodes {
		u := node.id
		for _, edge := range adj[u] {
			isNeighbor[edge.to] = true
		}

		popped := make([]Item, 0)
		for h.Len() > 0 {
			top := heap.Pop(h).(Item)
			if isNeighbor[top.u] {
				popped = append(popped, top)
			} else {
				val := top.A + B[u]
				if val > M {
					M = val
				}
				heap.Push(h, top)
				break
			}
		}

		for _, item := range popped {
			heap.Push(h, item)
		}

		heap.Push(h, Item{u: u, A: A[u]})

		for _, edge := range adj[u] {
			isNeighbor[edge.to] = false
		}
	}

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	for i := 0; i < m; i++ {
		x := nextInt64()
		ans := M + x
		if D < ans {
			ans = D
		}
		fmt.Fprintln(writer, ans)
	}
}