cin >> n >> k; for (int i = 1; i < n; ++i) { int x, y, z; cin >> x >> y >> z; S[y].insert({ x, z }); S[x].insert({ y, z }); } priority_queue<Queue> Q; for (int i = 1; i <= n; ++i) if (S[i].size() == 1) Q.push({ i, S[i].begin() -> second }); int ans = 0; while (Q.size() > 2 || k < n) { int u = Q.top().k, v; ans = Q.top().v; Q.pop(); --n; v = S[u].begin() -> first; S[v].erase(S[v].lower_bound({ u, 0 })); if (S[v].size() == 1) Q.push({ v, ans + S[v].begin() -> second }); } cout << ans << "\n"; return0; }