#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, k;   vector<vector<long long>> adj, leaf;   vector<long long> level, par, out;   vector<long long> counti;   void dfs(int src, int lvl, int p = -1) {     int child = 0;     level[src] = lvl;     for (auto it : adj[src]) {       if (it == p) continue;       par[it] = src;       child++;       dfs(it, lvl + 1, src);     }     if (!child) leaf.push_back({src, lvl, 0});     out[src] = child;   }   class comp {    public:     bool operator()(vector<long long> a, vector<long long> b) {       return a[1] - a[2] < b[1] - b[2];     }   };   void solve() {     cin >> n >> k;     adj.resize(n);     for (int i = 0, x, y; i < n - 1; i++) {       cin >> x >> y;       x--, y--;       adj[x].push_back(y);       adj[y].push_back(x);     }     level.resize(n);     par.resize(n);     out.resize(n);     dfs(0, 0);     vector<long long> total(n, 0);     priority_queue<vector<long long>, vector<vector<long long>>, comp> pq;     for (auto it : leaf) pq.push(it);     long long ans = 0;     while (!pq.empty() && k--) {       auto f = pq.top();       pq.pop();       long long node = f[0];       ans += f[1] - total[node];       if (node) {         total[par[node]] += f[2] + 1;         --out[par[node]];         if (!out[par[node]]) {           pq.push({par[node], f[1] - 1, total[par[node]]});         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }   