#include using namespace std; #define rep(i, n) for(int(i)=0;(i)<(n);(i)++) int main() { int n, k; cin >> n >> k; if(n < k) cout << -1 << endl; else { vector> G(n); rep(i, n-1) { int a, b; cin >> a >> b; a--;b--; G[a].emplace_back(b); G[b].emplace_back(a); } queue> que; long long total = 0LL; que.emplace(make_pair(0, -1)); vector used(n); int num = 0; while(!que.empty()) { pair p = que.front();que.pop(); used[p.first] = 1; total += (long long)(p.second + 1); num++; if(num == k) break; for(auto next_v : G[p.first]) { if(used[next_v]) continue; que.emplace(make_pair(next_v, p.second+1)); } } cout << total << endl; } }