#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int32_t n, k; cin >> n >> k; vector> tr(n); for (auto i = 0; i < n - 1; ++i) { int32_t a, b; cin >> a >> b; --a; --b; tr[a].push_back(b); tr[b].push_back(a); } if (k > n) { cout << -1 << endl; return 0; } int64_t ans = 0; queue> que; que.push({0, 0}); vector visited(n); visited[0] = true; --k; while (k > 0) { auto p = que.front(); que.pop(); int32_t cnt = 0; for (auto v : tr[p.first]) { if (visited[v]) continue; ++cnt; que.push({v, p.second + 1}); visited[v] = true; --k; if (k == 0) break; } if (cnt == 0) ans += p.second; } while (!que.empty()) { ans += que.front().second; que.pop(); } cout << ans << endl; return 0; }