import java.util.*; public class Main { static ArrayList> graph = new ArrayList<>(); static int[] values; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); graph.add(new HashMap<>()); } for (int i = 0; i < n - 1; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); graph.get(a).put(b, c); graph.get(b).put(a, c); } System.out.println(dfw(0, 0, m).lastEntry().getValue()); } static TreeMap dfw(int idx, int parent, int time) { graph.get(idx).remove(parent); TreeMap tmp = new TreeMap<>(); if (time < 0) { return tmp; } tmp.put(0, values[idx]); for (int x : graph.get(idx).keySet()) { int cost = graph.get(idx).get(x) * 2; TreeMap next = dfw(x, idx, time - cost); Integer key = Integer.MAX_VALUE; while ((key = tmp.lowerKey(key)) != null) { for (int y : next.keySet()) { if (cost + y + key > time) { break; } int value = tmp.get(key) + next.get(y); if (tmp.floorEntry(cost + y + key).getValue() < value) { tmp.put(cost + y + key, value); Integer mask = cost + y + key; while ((mask = tmp.higherKey(mask)) != null) { if (tmp.get(mask) <= value) { tmp.remove(mask); } else { break; } } } } } } return tmp; } }