#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define endl '\n'
int main()
{
#ifdef HOME
assert(freopen("input.in", "r", stdin));
// assert(freopen("output.out", "w", stdout));
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int n; cin >> n;)
{
vector<vector<int>> tree(n);
for (int i = 1; i < n; ++i)
{
int u, v;
cin >> u >> v;
tree[--u].push_back(--v);
tree[v].push_back(u);
}
if (n == 2)
{
cout << "1\n1 2\n";
continue;
}
vector<int> size(n), mx(n), leaves;
function<int(int, int)> dfs = [&](int u, int p)
{
size[u] = mx[u] = (tree[u].size() == 1);
for (int v : tree[u]) if (v != p)
{
size[u] += dfs(v, u);
mx[u] = max(mx[u], size[v]);
}
if (tree[u].size() == 1)
leaves.push_back(u);
return size[u];
};
dfs(0, 0);
for (int u = 0; u < n; ++u)
if (2 * max(mx[u], (int) leaves.size() - size[u]) < leaves.size())
{
leaves.clear();
dfs(u, u);
break;
}
cout << (leaves.size() + 1) / 2 << endl;
for (int i = 0, s = (leaves.size() + 1) / 2; i < s; ++i)
cout << leaves[i] + 1 << " " << leaves[(i + s) % leaves.size()] + 1 << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvYWxnb3JpdGhtPgojaW5jbHVkZSA8ZXh0L251bWVyaWM+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBuYW1lc3BhY2UgX19nbnVfY3h4OwoKI2RlZmluZSBlbmRsICdcbicKCmludCBtYWluKCkKewojaWZkZWYgSE9NRQoJYXNzZXJ0KGZyZW9wZW4oImlucHV0LmluIiwgInIiLCBzdGRpbikpOwoJLy8gYXNzZXJ0KGZyZW9wZW4oIm91dHB1dC5vdXQiLCAidyIsIHN0ZG91dCkpOwojZW5kaWYKCglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwoJY2luLnRpZSgwKTsKCglmb3IgKGludC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