#include <bits/stdc++.h>
using namespace std;
vector<int> graph[5000];
bool visited[5000];
int co = 0;
int dfs(int i, int p = 0) {
  int s = 1;
  for (auto x : graph[i]) {
    if (x != p) s += dfs(x, i);
  }
  return s;
}
void here_we_go_again() {
  int n, m, x, y, i;
  cin >> n;
  m = n - 1;
  while (m--) {
    cin >> x >> y;
    x--, y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  bitset<5001> a, tmp;
  for (i = 0; i < n; i++) {
    tmp = 0;
    for (auto x : graph[i]) {
      int s = dfs(x, i);
      tmp = tmp | (tmp << s);
      tmp[s] = true;
    }
    a = a | tmp;
  }
  cout << a.count() - a[n - 1] - a[0] << "\n";
  for (i = 1; i < n - 1; i++)
    if (a[i]) cout << i << " " << n - 1 - i << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) here_we_go_again();
  return 0;
}
