#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; while (k > 0) { auto p = que.front(); que.pop(); ans += p.second; --k; for (auto v : tr[p.first]) { if (visited[v]) continue; que.push({v, p.second + 1}); visited[v] = true; } } cout << ans << endl; return 0; }