#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() using namespace std; typedef long long int ll; typedef pair P; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector

vp; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 vector pre_G[MAX_N]; vector G[MAX_N]; int par_[MAX_N]; int flag_netsukigi[MAX_N]; void make_netsukigi(int r){ queue que; que.push(r); flag_netsukigi[r] = 1; par_[r] = -1; while(que.size() > 0){ int x = que.front(); que.pop(); flag_netsukigi[x] = 1; rep(i,pre_G[x].size()){ if(flag_netsukigi[pre_G[x][i]] == 0){ par_[pre_G[x][i]] = x; G[x].push_back(pre_G[x][i]); que.push(pre_G[x][i]); } } } } int main() { int n , k; cin >> n >> k; rep(i,n-1){ int a, b; scanf("%d%d", &a, &b); a--; b--; // 0-indexにするため. pre_G[a].push_back(b); pre_G[b].push_back(a); } make_netsukigi(0); if(n < k){ cout << -1<< endl; return 0; } int z[n] = {}; queue que; que.push(0); while(que.size() > 0){ int x = que.front(); que.pop(); rep(i,G[x].size()){ z[G[x][i]] = z[i] + 1; que.push(G[x][i]); } } sort(z,z+n); ll ans = 0; rep(i,k){ ans += z[i]; } cout << ans << endl; return 0; }