#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using lld = long double;
const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 5050;
vector<int> adj[N], siz(N, 0);
set<int> hs;
set<int> _left;
int n;
void dfs(int src, int par) {
  vector<int> tmp;
  for (int i : adj[src]) {
    if (i == par) continue;
    dfs(i, src);
    int p = siz[i];
    siz[src] += p;
    tmp.emplace_back(p);
  }
  siz[src]++;
  if (n - siz[src]) tmp.emplace_back(n - siz[src]);
  if (tmp.size() > 1) {
    bitset<N> dp;
    dp[0] = 1;
    for (int i : tmp) dp |= (dp << i);
    vector<int> to_erase;
    for (int j : _left)
      if (dp[j]) to_erase.emplace_back(j);
    for (int j : to_erase) _left.erase(j);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n - 1; ++i) _left.insert(i);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  set<pair<int, int> > ans;
  dfs(0, 0);
  for (int j = 1; j < n - 1; j++) {
    if (_left.count(j)) continue;
    ans.emplace(n - 1 - j, j);
    ans.emplace(j, n - 1 - j);
  }
  cout << ((int)(ans).size()) << "\n";
  for (auto [a, b] : ans) cout << a << " " << b << '\n';
  return 0;
}
