#include #include #include #include #include #include #define pii pair using namespace std; int n, tata[100100]; long long K, target, sum[100100]; vector G[100100]; inline long long BinarySearch(int lvl) { int st, dr, mij, rez; st = 0; dr = lvl; rez = lvl; while(st <= dr) { mij = (st + dr) / 2; if(sum[lvl] - sum[mij] <= target) { rez = mij; dr = mij - 1; } else st = mij + 1; } return (lvl - rez); } inline long long Count(int x, int lvl) { long long cnt = 0LL; vector ::iterator it; for(it = G[x].begin(); it != G[x].end(); ++it) { if((*it).first != tata[x]) { tata[(*it).first] = x; sum[lvl] = sum[lvl - 1] + 1LL * (*it).second; cnt += BinarySearch(lvl); cnt += Count((*it).first, lvl + 1); } } return cnt; } inline long long Search() { long long st, dr, mij, rez; st = 0; dr = 2000000000; rez = -1; while(st <= dr) { mij = (st + dr) / 2LL; target = mij; if(Count(1, 1) >= K) { rez = mij; dr = mij - 1LL; } else st = mij + 1LL; } return rez; } int main() { int i, x, y, cost; std::ios_base::sync_with_stdio(false); cin >> n >> K; for(i = 1; i < n; ++i) { cin >> x >> y >> cost; G[x].push_back(make_pair(y, cost)); G[y].push_back(make_pair(x, cost)); } tata[1] = -1; cout << Search() << "\n"; return 0; }