func_code_string: #include <bits/stdc++.h>   using namespace std;   std::vector<int> res;   std::vector<int> adj[200005];   std::vector<int> DEPTH(200005);   std::vector<int> NODENUM(200005);   std::vector<int> funct(200005);   vector<bool> taken(200005);   vector<bool> visited(200005);   int dfs(int v, int depth) {     int nodeNum = 0;     visited[v] = 1;     DEPTH[v] = depth;     for (int u : adj[v]) {       if (!visited[u]) {         nodeNum += dfs(u, depth + 1);       }     }     NODENUM[v] = nodeNum;     return NODENUM[v] + 1;   }   long long dfsV2(int v) {     visited[v] = 1;     long long ans = 0;     for (int u : adj[v]) {       if (!visited[u]) {         if (taken[u]) {           ans += (long long)(NODENUM[u] + 1) * DEPTH[u];         } else           ans += (long long)dfsV2(u);       }     }     return ans;   }   bool func(int x, int y) {     if (funct[x] > funct[y]) return true;     return false;   }   void solve() {     int n, k, x, y, i;     cin >> n >> k;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, 0);     for (i = 1; i <= n; i++) {       funct[i] = DEPTH[i] - NODENUM[i];       res.push_back(i);     }     sort(res.begin(), res.end(), func);     for (i = 0; i < k; i++) {       taken[res[i]] = 1;     }     for (i = 0; i < n + 2; i++) {       visited[i] = 0;     }     cout << dfsV2(1) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     solve();     return 0;   }   