#include <bits/stdc++.h>
using namespace std;
FILE *outt, *inn;
const int N = 5000 + 5, M = 500;
int n, m, dp[N];
bool mark[N], is[N];
set<int> s;
vector<int> v[N];
void dfs(int x) {
  mark[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (!mark[v[x][i]]) {
      dfs(v[x][i]);
      mark[v[x][i]] = 0;
      dp[x] += dp[v[x][i]] + 1;
    }
  }
  memset(is, 0, sizeof(is));
  is[0] = is[n - dp[x] - 1] = 1;
  int id;
  for (int i = 0; i < v[x].size(); i++) {
    if (!mark[v[x][i]]) {
      id = dp[v[x][i]] + 1;
      for (int j = n; j >= 0; --j)
        if (is[j] && id + j <= n) is[id + j] = 1;
    }
  }
  for (int i = 1; i < (n - 1); i++) {
    if (is[i]) s.insert(i);
  }
}
int main() {
  scanf("%d", &n);
  int a, b;
  for (int i = 1; i < n; i++) {
    scanf("%d", &a), scanf("%d", &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1);
  cout << s.size() << endl;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    cout << (*it) << " " << (n - 1 - *it) << endl;
    ;
  }
}
