#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, t1, t2, r = 0, l = 0;
vector<ll> adj[500005];
vector<ll> st[500005];
vector<pll> res;
void dfs(ll nd, ll pr) {
if (adj[nd].size() == 1) {l++, st[nd].push_back(nd); return;}
for (auto it : adj[nd]) if (it != pr) dfs(it, nd);
vector<ll> tp;
for (auto it : adj[nd]) if (it != pr) {
if (st[it].size() == 1) {tp.push_back(it); continue;}
if (!st[nd].size()) {swap(st[nd], st[it]); continue;}
res.push_back({st[nd].back(), st[it].back()});
st[nd].pop_back();
st[it].pop_back();
if (st[nd].size() < st[it].size()) swap(st[nd], st[it]);
for (auto it2 : st[it]) st[nd].push_back(it2);
}
for (auto it : tp) {
if (!st[nd].size()) {swap(st[nd], st[it]); continue;}
res.push_back({st[nd].back(), st[it].back()});
st[nd].pop_back();
st[it].pop_back();
if (st[nd].size() < st[it].size()) swap(st[nd], st[it]);
for (auto it2 : st[it]) st[nd].push_back(it2);
}
if (nd != r && !st[nd].size()) {
st[nd].push_back(res.back().first);
st[nd].push_back(res.back().second);
res.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
iloop(1, n) {
cin >> t1 >> t2;
t1--, t2--;
adj[t1].push_back(t2);
adj[t2].push_back(t1);
}
while (adj[r].size() == 1) r++;
dfs(r, -1);
cout << (l+1)/2 << "\n";
for (auto it : res) cout << it.first + 1 << " " << it.second + 1 << "\n";
iloop(0, (ll)st[r].size()/2) cout << st[r][2*i] + 1 << " " << st[r][2*i+1] + 1 << "\n";
if (l%2 == 1) cout << st[r].back() + 1 << " " << r + 1 << "\n";
}