#include #include #include #include using namespace std; int main() { // Reading the input. int n, p; cin >> n >> p; vector> adj(n); for(int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } // Make a list of all the leaves in DFS order. stack s; s.push(0); vector leaves; vector visited(n, false); visited[0] = true; while(!s.empty()) { int cur = s.top(); s.pop(); if(adj[cur].size() == 1) leaves.push_back(cur); for(int nb : adj[cur]) { if(!visited[nb]) { visited[nb] = true; s.push(nb); } } } // Now simply connect leaf i with leaf i + #leaves/2. int nleaves = leaves.size(); cout << (nleaves + 1) / 2 << endl; for(int i = 0; i < nleaves / 2; i++) { cout << leaves[i] << " " << leaves[i + nleaves / 2] << endl; } // If we have an odd number of leaves, we have to connect the final one too. if(nleaves & 1) { cout << leaves[0] << " " << leaves[nleaves - 1] << endl; } return 0; }