#include <bits/stdc++.h>
using namespace std;
const int N = 5100;
struct Edge {
  int v, next;
  Edge() {}
  Edge(int v, int next) : v(v), next(next) {}
} e[N * 2];
int head[N], total;
void init() {
  memset(head, -1, sizeof(head));
  total = 0;
}
void adde(int u, int v) {
  e[total] = Edge(v, head[u]);
  head[u] = total++;
}
int num[N];
int dp[N][N], biao[N];
int n;
void dfs(int u, int f) {
  num[u] = 0;
  dp[u][0] = 1;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == f) continue;
    dfs(v, u);
    for (int j = num[u]; j >= 0; j--)
      if (dp[u][j]) {
        dp[u][j + num[v]] = 1;
      }
    num[u] += num[v];
  }
  for (int j = num[u]; j >= 0; j--)
    if (dp[u][j]) {
      dp[u][n - 1 - num[u] + j] = 1;
    }
  for (int j = n - 1; j >= 0; j--) {
    biao[j] |= dp[u][j];
  }
  num[u]++;
}
int sta[N], top;
int main() {
  while (scanf("%d", &n) != EOF) {
    init();
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      adde(a, b);
      adde(b, a);
    }
    memset(dp, 0, sizeof(dp));
    memset(biao, 0, sizeof(biao));
    dfs(1, 0);
    top = 0;
    for (int i = 1; i < n - 1; i++)
      if (biao[i]) {
        sta[top++] = i;
      }
    printf("%d\n", top);
    for (int i = 0; i < top; i++) {
      printf("%d %d\n", sta[i], n - 1 - sta[i]);
    }
  }
  return 0;
}
