#include <bits/stdc++.h>
using namespace std;
const int MXN = 5001;
const int INF = 1e9 + 7;
int n;
vector<int> v[MXN];
int down[MXN];
bool u[MXN];
set<pair<int, int> > res;
void dfs1(int x, int p = -1) {
  down[x] = 1;
  for (auto go : v[x]) {
    if (p == go) continue;
    dfs1(go, x);
    down[x] += down[go];
  }
}
void dfs(int x, int p = -1) {
  vector<int> q;
  for (auto go : v[x]) {
    if (p == go) continue;
    dfs(go, x);
    q.push_back(down[go]);
  }
  if (q.empty()) return;
  memset(u, 0, sizeof u);
  if (p > 0) q.push_back(n - down[x]);
  u[0] = 1;
  for (auto it : q) {
    for (int second = n - 2; second >= 1; second--) {
      if (second - it < 0) continue;
      if (u[second - it]) {
        u[second] = 1;
        res.insert({n - 1 - second, second});
        res.insert({second, n - 1 - second});
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs1(1);
  dfs(1);
  printf("%d\n", (int)res.size());
  for (auto it : res) {
    printf("%d %d\n", it.first, it.second);
  }
  return 0;
}
