N, K = map(int, input().split()) v = [[[], []] for _ in range(N)] weight = [] for i in range(N-1): a, b, c = map(int, input().split()) v[a-1][1].append((b-1, i)) v[b-1][1].append((a-1, i)) weight.append(c) q = [(0, [])] e = [0] * (N-1) while len(q) > 0: i, c = q.pop(0) v[i][0] = c cnt = True for j, k in v[i][1]: if j == 0 or len(v[j][0]) > 0: continue cnt = False q.append((j, c+[k])) if cnt: for j in c: e[j] += 1 dp = [[0] * (K+1) for _ in range(N)] for i in range(N-1): for w in range(K+1): if w >= weight[i]: dp[i+1][w] = max(dp[i+1][w-weight[i]] + weight[i] * e[i], dp[i][w] + weight[i] * e[i]) else: dp[i+1][w] = dp[i][w] + weight[i] * e[i] print(dp[N-1][K])