#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e, long long m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
vector<vector<int>> v, v2;
vector<bool> check;
int a[5005];
vector<bool> dp;
void dfs(int x) {
  check[x] = true;
  a[x] = 1;
  for (auto i : v[x]) {
    if (!check[i]) {
      dfs(i);
      a[x] += a[i];
    }
  }
}
void dfs2(int x) {
  check[x] = true;
  for (auto i : v[x]) {
    if (!check[i]) {
      v2[x].push_back(a[i]);
      dfs2(i);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  v.resize(n + 1);
  check.resize(n + 1);
  v2.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  check.clear();
  check.resize(n + 1);
  dfs2(1);
  for (int i = 1; i <= n; i++) {
    if ((n - a[i]) != 0) v2[i].push_back(n - a[i]);
  }
  set<int> ss;
  for (int i = 1; i <= n; i++) {
    dp.clear();
    dp.resize(5005);
    dp[0] = 1;
    for (auto j : v2[i]) {
      for (int k = 5001; k >= 0; k--) {
        if ((k - j) >= 0 && dp[k - j]) {
          dp[k] = true;
          ss.insert(k);
        }
      }
    }
  }
  set<pair<int, int>> s;
  for (auto i : ss) {
    if ((n - i - 1) != 0) s.insert({i, n - i - 1});
  }
  cout << s.size() << "\n";
  for (auto i : s) cout << i.first << " " << i.second << "\n";
  return 0;
}
