#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int n;
vector<int> edge[maxn];
vector<int> children[maxn];
bool final[maxn], cur[maxn], done[maxn];
int getCount(int u) {
  done[u] = true;
  int c, sum = 0;
  for (int i = 0; i < edge[u].size(); i++) {
    if (done[edge[u][i]]) continue;
    c = getCount(edge[u][i]);
    children[u].push_back(c);
    sum += c;
  }
  children[u].push_back(n - sum - 1);
  return sum + 1;
}
void ballsac(int u) {
  if (children[u][0] == 0 || children[u][0] == n - 1) {
    return;
  }
  for (int i = 1; i < n; i++) {
    cur[i] = false;
  }
  cur[0] = true;
  for (int i = 0; i < children[u].size(); i++) {
    for (int j = n; j >= children[u][i]; j--) {
      if (cur[j - children[u][i]]) {
        final[j] = cur[j] = true;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int t = getCount(0);
  for (int i = 0; i < n; i++) {
    ballsac(i);
  }
  int o = 0;
  for (int i = 1; i < n - 1; i++) {
    if (final[i] || final[n - i - 1]) {
      o++;
    }
  }
  printf("%d\n", o);
  for (int i = 1; i < n - 1; i++) {
    if (final[i] || final[n - i - 1]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
  return 0;
}
