import java.util.*; import java.io.*; public class Main { static int m; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); m = Integer.parseInt(first[1]) + 1; Node[] tree = new Node[n]; for (int i = 0; i < n; i++) { tree[i] = new Node(i, Integer.parseInt(br.readLine())); } for (int i = 0; i < n - 1; i++) { String[] line = br.readLine().split(" ", 3); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); int c = Integer.parseInt(line[2]); tree[a].add(tree[b], c); tree[b].add(tree[a], c); } int[] arr = tree[0].getArray(null); Arrays.sort(arr); System.out.println(arr[m - 1]); } static void printArrray(int[] arr) { StringBuilder sb = new StringBuilder(); for (int x : arr) { sb.append(x).append(" "); } System.out.println(sb); } static class Node { int id; HashMap paths = new HashMap<>(); int[] costs = new int[m]; public Node(int id, int cost) { this.id = id; costs[0] = cost; } public void add(Node n, int cost) { paths.put(n, cost); } public int[] getArray(Node parent) { if (parent != null) { paths.remove(parent); } for (Map.Entry p : paths.entrySet()) { int[] tmp = new int[m]; int[] child = p.getKey().getArray(this); int added = p.getValue() * 2; for (int i = 0; i < m - added; i++) { for (int j = 0; j < m - i - added; j++) { tmp[i + j + added] = Math.max(tmp[i + j + added] , costs[i] + child[j]); } } for (int i = 0; i < m; i++) { costs[i] = Math.max(costs[i], tmp[i]); } } return costs; } public int hashCode() { return id; } public boolean equals(Object o) { Node n = (Node) o; return id == n.id; } } }