#include typedef struct List { struct List *next; int v, cost; } list; void chmax(long long* a, long long b) { if (*a < b) *a = b; } int main() { int i, N, K, u, w, c; list *adj[101] = {}, e[201], *p; scanf("%d %d", &N, &K); for (i = 0; i < N - 1; i++) { scanf("%d %d %d", &u, &w, &c); e[i*2].v = w; e[i*2+1].v = u; e[i*2].cost = c; e[i*2+1].cost = c; e[i*2].next = adj[u]; e[i*2+1].next = adj[w]; adj[u] = &(e[i*2]); adj[w] = &(e[i*2+1]); } int par[101] = {}, depth[101], q[101], head, tail; par[1] = 1; depth[1] = 0; q[0] = 1; for (head = 0, tail = 1; head < tail; head++) { u = q[head]; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (par[w] == 0) { par[w] = u; depth[w] = depth[u] + p->cost; q[tail++] = w; } } } long long dp[101][100001] = {}, tmp[100001], leaf[101] = {}; for (head--; head >= 0; head--) { u = q[head]; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; c = p->cost; if (w == par[u]) continue; leaf[u] += leaf[w]; for (i = 0; i <= K; i++) tmp[i] = dp[w][i]; for (i = c; i <= K; i++) chmax(&(tmp[i]), dp[w][i-c] + c * leaf[w]); for (i = 0; i <= K; i++) dp[u][i] += tmp[i]; } if (leaf[u] == 0) { leaf[u] = 1; dp[u][0] = depth[u]; } } long long ans = 0; for (i = 0; i <= K; i++) chmax(&ans, dp[1][i]); printf("%lld\n", ans); fflush(stdout); return 0; }