#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 5010;
int n;
vector<int> adjl[max_n];
bool visited[max_n] = {0};
bool res[max_n] = {0};
int nres;
vector<int> v[max_n];
bool dp[max_n];
int nst[max_n];
void go(vector<int>& cv) {
  fill(dp + 1, dp + n, false);
  dp[0] = true;
  for (int i = 0; i < (int)cv.size(); ++i) {
    for (int j = n - 1; j >= cv[i]; --j) dp[j] = (dp[j] or dp[j - cv[i]]);
  }
  for (int i = 0; i < n; ++i) res[i] = (res[i] or dp[i]);
}
void DFS(int vt) {
  visited[vt] = true;
  nst[vt] = 1;
  int nb;
  for (int i = 0; i < (int)adjl[vt].size(); ++i) {
    nb = adjl[vt][i];
    if (not visited[nb]) {
      DFS(nb);
      nst[vt] += nst[nb];
      v[vt].push_back(nst[nb]);
    }
  }
  if (vt != 0) v[vt].push_back(n - nst[vt]);
  go(v[vt]);
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d", &u);
    scanf("%d", &v);
    --u;
    --v;
    adjl[u].push_back(v);
    adjl[v].push_back(u);
  }
  DFS(0);
  for (int i = 1; i < n - 1; ++i) nres += res[i];
  printf("%d\n", nres);
  for (int i = 1; i < n - 1; ++i) {
    if (res[i]) {
      printf("%d ", i);
      printf("%d\n", n - 1 - i);
    }
  }
  return 0;
}
