#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> out[7500];
vector<int> size[7500];
map<pair<int, int>, int> sizes;
bool ok[7500];
void get_input() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    out[a].push_back(b);
    out[b].push_back(a);
    size[a].push_back(-1);
    size[b].push_back(-1);
  }
  for (int i = 0; i <= n; i++) ok[i] = false;
}
int get_size(int v, int par) {
  if (sizes[make_pair(par, v)] > 0) return sizes[make_pair(par, v)];
  if (sizes[make_pair(v, par)] > 0) {
    sizes[make_pair(par, v)] = n - sizes[make_pair(v, par)];
    return sizes[make_pair(par, v)];
  }
  int total = 1;
  for (int i = 0; i < out[v].size(); i++) {
    if (out[v][i] == par) continue;
    total += get_size(out[v][i], v);
  }
  return sizes[make_pair(par, v)] = total;
}
void tree_sizes() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < out[i].size(); j++) {
      size[i][j] = get_size(out[i][j], i);
    }
  }
}
void process() {
  for (int i = 1; i <= n; i++) {
    int size_list[n + 1];
    size_list[0] = 0;
    int len = 1;
    for (int j = 0; j < out[i].size(); j++) {
      int size_list2[len];
      for (int k = 0; k < len; k++) {
        size_list2[k] = size_list[k] + size[i][j];
      }
      int nlen = 0;
      int size_merge[2 * len];
      int i1 = 0, i2 = 0;
      while (i1 != len || i2 != len) {
        if (i1 == len) {
          size_merge[nlen++] = size_list2[i2++];
        } else {
          if (size_list[i1] < size_list2[i2]) {
            size_merge[nlen++] = size_list[i1++];
          } else if (size_list[i1] > size_list2[i2]) {
            size_merge[nlen++] = size_list2[i2++];
          } else {
            size_merge[nlen++] = size_list2[i2++];
            i1++;
          }
        }
      }
      for (int k = 0; k < nlen; k++) {
        size_list[k] = size_merge[k];
      }
      len = nlen;
    }
    for (int j = 0; j < len; j++) {
      ok[size_list[j]] = true;
    }
  }
}
void print_ans() {
  int num = 0;
  for (int i = 1; i <= n - 2; i++) {
    if (ok[i]) num++;
  }
  printf("%d\n", num);
  for (int i = 1; i <= n - 2; i++) {
    if (ok[i]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
}
int main() {
  get_input();
  tree_sizes();
  process();
  print_ans();
}
