#include <bits/stdc++.h>
using namespace std;
const int MX = 5005;
bool temDp[MX], perDp[MX];
int n, sz[MX];
vector<int> adj[MX];
bool vis[MX];
void Dfs(int v) {
  vis[v] = true;
  sz[v] = 1;
  vector<int> part;
  for (int i = 0; i < (int)adj[v].size(); ++i) {
    int u = adj[v][i];
    if (!vis[u]) {
      Dfs(u);
      part.push_back(sz[u]);
      sz[v] += sz[u];
    }
  }
  if (v != 1) {
    part.push_back(n - sz[v]);
  }
  for (int i = 1; i <= n; ++i) {
    temDp[i] = false;
  }
  temDp[0] = true;
  for (int i = 0; i < (int)part.size(); ++i) {
    int x = part[i];
    for (int a = n; a >= x; --a) {
      if (temDp[a - x]) {
        temDp[a] = true;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (temDp[i]) {
      perDp[i] = true;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  Dfs(1);
  int nb = 0;
  for (int a = 1; a <= n - 2; ++a) {
    if (perDp[a]) {
      ++nb;
    }
  }
  printf("%d\n", nb);
  for (int a = 1; a <= n - 2; ++a) {
    if (perDp[a]) {
      printf("%d %d\n", a, n - 1 - a);
    }
  }
  return 0;
}
