func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, prnt[N];   long long k;   long long sum = 0;   vector<int> g[N];   int sz[N];   void DFS(int node, int prnt) {     sz[node] = 1;     for (int i = 0; i < (int)g[node].size(); i++) {       if (g[node][i] == prnt) continue;       DFS(g[node][i], node);       sz[node] += sz[g[node][i]];     }   }   int get_centroid(int node, int prnt) {     for (int i = 0; i < (int)g[node].size(); i++) {       if (g[node][i] == prnt) continue;       if (sz[g[node][i]] > n / 2) return get_centroid(g[node][i], node);     }     return node;   }   int Idx, cur[N], in[N], depth[N], val[N], root;   bool taken[N];   void init(int node) {     cur[node] = Idx;     val[Idx]++;     sum += depth[node];     for (int i = 0; i < (int)g[node].size(); i++) {       if (g[node][i] == prnt[node]) continue;       depth[g[node][i]] = depth[node] + 1;       prnt[g[node][i]] = node;       init(g[node][i]);       in[node]++;     }   }   vector<int> has[N];   priority_queue<pair<int, int> > q[N];   set<pair<int, int> > st[N];   set<pair<int, int> >::iterator it, it2;   vector<pair<int, int> > ans;   priority_queue<pair<int, int> > pq, q2;   void finish(int node) {     it2 = st[cur[node]].find(make_pair(depth[node], node));     if (it2 != st[cur[node]].end()) st[cur[node]].erase(it2);     int idx = -1;     for (int i = 0; i < (int)g[node].size(); i++) {       if (g[node][i] == prnt[node]) continue;       if (idx == -1 ||           (int)has[g[node][i]].size() > (int)has[g[node][idx]].size()) {         idx = i;       }     }     if (idx != -1) swap(has[node], has[g[node][idx]]);     for (int i = 0; i < (int)g[node].size(); i++) {       if (i == idx || g[node][i] == prnt[node]) continue;       while ((int)has[g[node][i]].size() > 0) {         has[node].push_back(has[g[node][i]].back());         has[g[node][i]].pop_back();       }     }     if (!taken[node]) has[node].push_back(node);     if (prnt[node] == root) return;     in[prnt[node]]--;     if ((int)has[node].size() > 0)       q[prnt[node]].push(make_pair((int)has[node].size(), node));     if (in[prnt[node]] == 0) {       st[cur[node]].insert(make_pair(depth[prnt[node]], prnt[node]));     }   }   vector<int> lll;   int main() {     scanf( %d%lld , &n, &k);     for (int u, v, i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     DFS(1, -1);     root = get_centroid(1, -1);     prnt[root] = -1;     for (int i = 0; i < (int)g[root].size(); i++) {       Idx = i;       prnt[g[root][i]] = root;       depth[g[root][i]] = 1;       init(g[root][i]);       in[root]++;       pq.push(make_pair(val[Idx], Idx));     }     if (k > sum || (sum % 2) != (k % 2)) {       puts( NO );       return 0;     }     for (int i = 1; i <= n; i++) {       if (in[i] == 0) {         lll.push_back(i);       }     }     for (int i = 0; i < (int)lll.size(); i++) {       finish(lll[i]);     }     int tmp1, tmp2, tmp3, tmp4;     long long needed;     while (sum > k && (int)pq.size() > 0) {       tmp1 = pq.top().second;       pq.pop();       if (val[tmp1] < 2) break;       needed = (sum - k) / 2;       assert((int)st[tmp1].size() > 0);       while (true) {         it = st[tmp1].end();         it--;         tmp2 = it->second;         if ((long long)it->first > needed) {           finish(tmp2);           continue;         }         if ((int)q[tmp2].size() > 1) {           tmp3 = q[tmp2].top().second;           q[tmp2].pop();           tmp4 = q[tmp2].top().second;           q[tmp2].pop();           ans.push_back(make_pair(has[tmp3].back(), has[tmp4].back()));           taken[has[tmp3].back()] = taken[has[tmp4].back()] = true;           has[tmp3].pop_back();           has[tmp4].pop_back();           if ((int)has[tmp3].size() > 0)             q[tmp2].push(make_pair((int)has[tmp3].size(), tmp3));           if ((int)has[tmp4].size() > 0)             q[tmp2].push(make_pair((int)has[tmp4].size(), tmp4));           sum -= (long long)2 * depth[tmp2];           break;         }         if (taken[tmp2] || (int)q[tmp2].size() == 0) {           finish(tmp2);           continue;         }         tmp3 = q[tmp2].top().second;         q[tmp2].pop();         ans.push_back(make_pair(tmp2, has[tmp3].back()));         taken[tmp2] = true;         taken[has[tmp3].back()] = true;         has[tmp3].pop_back();         finish(tmp2);         sum -= (long long)2 * depth[tmp2];         break;       }       val[tmp1] -= 2;       if (val[tmp1] > 0) pq.push(make_pair(val[tmp1], tmp1));     }     for (int i = 1; i <= n; i++) has[i].clear();     for (int i = 1; i <= n; i++) {       if (i != root && !taken[i]) has[cur[i]].push_back(i);     }     for (int i = 0; i < (int)g[root].size(); i++) {       if ((int)has[i].size() > 0) q2.push(make_pair((int)has[i].size(), i));     }     while ((int)q2.size() > 1) {       tmp1 = q2.top().second;       q2.pop();       tmp2 = q2.top().second;       q2.pop();       ans.push_back(make_pair(has[tmp1].back(), has[tmp2].back()));       has[tmp1].pop_back();       has[tmp2].pop_back();       if ((int)has[tmp1].size() > 0)         q2.push(make_pair((int)has[tmp1].size(), tmp1));       if ((int)has[tmp2].size() > 0)         q2.push(make_pair((int)has[tmp2].size(), tmp2));     }     assert((int)q2.size() > 0);     tmp1 = q2.top().second;     tmp1 = has[tmp1].back();     ans.push_back(make_pair(root, tmp1));     if (sum == k) {       puts( YES );       assert((int)ans.size() == n / 2);       for (int i = 0; i < (int)ans.size(); i++) {         printf( %d %d n , ans[i].first, ans[i].second);       }     } else       puts( NO );     return 0;   }   