#include <bits/stdc++.h>
using namespace std;
int N;
int reach[5000 + 1];
bool CHECK[5000 + 1];
list<pair<int, int> > adj[5000];
int child[5000];
vector<int> res;
void foo(int s) {
  memset(reach, 0, sizeof reach);
  reach[0] = 1;
  int upperB = 0;
  int counter = 1;
  for (list<pair<int, int> >::iterator it = adj[s].begin(); it != adj[s].end();
       it++) {
    counter++;
    for (int i = 0; i <= upperB; i++)
      if (reach[i] && reach[i] < counter) {
        if (reach[i + it->second])
          reach[i + it->second] = min(reach[i + it->second], counter);
        else
          reach[i + it->second] = counter;
        upperB = min(N / 2, max(upperB, i + it->second));
      }
  }
  for (int i = 1; i <= N / 2 - (N % 2 == 0); i++)
    if (reach[i] && CHECK[i] == 0) {
      res.push_back(i);
      if (i != N - i - 1) res.push_back(N - i - 1);
      CHECK[i] = CHECK[N - i - 1] = 1;
    }
}
int getSub(int s, int a) {
  if (child[s] == 1) return 1;
  int tot = 0;
  for (list<pair<int, int> >::iterator it = adj[s].begin(); it != adj[s].end();
       it++)
    if (it->first != a) {
      if (!it->second) it->second = getSub(it->first, s);
      tot += it->second;
    }
  return tot + 1;
}
int main() {
  scanf("%d", &N);
  int i, a, b;
  for (i = 0; i < N - 1; i++) {
    scanf("%d %d", &a, &b);
    adj[a - 1].push_back(make_pair(b - 1, 0));
    adj[b - 1].push_back(make_pair(a - 1, 0));
    child[a - 1]++;
    child[b - 1]++;
  }
  for (i = 0; i < N; i++)
    for (list<pair<int, int> >::iterator it = adj[i].begin();
         it != adj[i].end(); it++) {
      if (!it->second) it->second = getSub(it->first, i);
    }
  for (i = 0; i < N; i++)
    if (child[i] > 1) {
      foo(i);
    }
  printf("%d\n", res.size());
  sort(res.begin(), res.end());
  for (vector<int>::iterator it = res.begin(); it != res.end(); it++)
    printf("%d %d\n", *it, N - 1 - *it);
  return 0;
}
