#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> a(n + 1);
vector<int> grad(n + 1, 0);
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
grad[x]++;
grad[y]++;
}
// caz special
if (n == 1) {
cout << 0 << '\n';
return 0;
}
// colectăm frunzele
vector<int> frunze;
for (int i = 1; i <= n; i++) {
if (grad[i] == 1) {
frunze.push_back(i);
}
}
int m = frunze.size();
// număr minim de muchii
cout << (m + 1) / 2 << '\n';
// pairing stabil
for (int i = 0; i < m / 2; i++) {
cout << frunze[i] << " " << frunze[i + m / 2] << '\n';
}
// dacă număr impar de frunze
if (m % 2 == 1) {
cout << frunze[0] << " " << frunze[m - 1] << '\n';
}
return 0;
}