#include #include #include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template using Graph = std::vector>>; using lint = long long; void solve() { int n, k; std::cin >> n >> k; Graph<> graph(n); for (int i = 0; i < n - 1; ++i) { int u, v; std::cin >> u >> v; --u, --v; graph[u].emplace_back(u, v); graph[v].emplace_back(v, u); } std::vector dist(n, 0); std::function dfs = [&](int v, int p, int d) { ++dist[d]; for (auto e : graph[v]) { int u = e.dst; if (u == p) continue; dfs(u, v, d + 1); } }; dfs(0, -1, 0); lint ans = 0; for (int d = 0; d < n; ++d) { lint r = std::min(dist[d], k); ans += r * d; k -= r; } std::cout << (k > 0 ? -1 : ans) << std::endl; } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }