#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
vector<long long> v[N];
vector<pair<long long, long long> > ans;
map<pair<long long, long long>, long long> m;
vector<long long> dp(N, 0);
long long n;
long long dfs(long long u, long long fp) {
  long long su = 0;
  long long i;
  vector<long long> val;
  for (auto child : v[u]) {
    if (child == fp) continue;
    long long tmp = dfs(child, u);
    val.push_back(tmp);
    su += tmp;
  }
  val.push_back(n - 1 - su);
  fill(dp.begin(), dp.end(), 0);
  dp[0] = 1;
  for (auto k : val) {
    long long tmp = k;
    for (i = n - 1; i >= 0; i--) {
      if (i + tmp <= n - 1 && dp[i] == 1) {
        dp[i + tmp] = 1;
      }
    }
  }
  for (i = 1; i < n - 1; i++) {
    if (dp[i]) {
      assert(dp[n - 1 - i] == 1);
      if (m[{i, n - 1 - i}] == 0 && m[{n - 1 - i, i}] == 0) {
        m[{i, n - 1 - i}] = 1;
        m[{n - 1 - i, i}] = 1;
        ans.push_back({i, n - 1 - i});
        if (i != n - 1 - i) ans.push_back({n - 1 - i, i});
      }
    }
  }
  return su + 1;
}
void test_case() {
  long long i;
  cin >> n;
  for (i = 1; i < n; i++) {
    long long p, q;
    cin >> p >> q;
    p--;
    q--;
    v[p].push_back(q);
    v[q].push_back(p);
  }
  dfs(0, -1);
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (auto k : ans) {
    cout << k.first << " " << k.second << "\n";
  }
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    test_case();
  }
  return 0;
}
