#include #include #include #include using namespace std; const int MAXN = 100005; bool Viz[MAXN]; int D[MAXN], Parent[MAXN][18]; int n; vector> G[MAXN]; void dfs(int node) { Viz[node] = 1; for(auto vec : G[node]) { if(!Viz[vec.first]) { D[vec.first] = D[node] + vec.second; Parent[vec.first][0] = node; for(int i = 1; Parent[vec.first][i - 1]; ++i) Parent[vec.first][i] = Parent[Parent[vec.first][i - 1]][i - 1]; dfs(vec.first); } } } long long solve(int k) { long long ans = 0; for(int node = 1; node <= n; ++node) { int aux = node; for(int i = 17; i >= 0; --i) if(Parent[aux][i] && D[node] - D[Parent[aux][i]] <= k) aux = Parent[aux][i], ans += (1 << i); } return ans; } int main() { int a, b, c; long long m; cin >> n >> m; for(int i = 2; i <= n; ++i) { cin >> a >> b >> c; G[a].push_back({b, c}); G[b].push_back({a, c}); } dfs(1); int ans = -1; for(int step = (1 << 29); step; step >>= 1) { if(solve(step + ans) < m) ans += step; } if(ans > 1e9) ans = -2; cout << ans + 1; return 0; }