#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
int n, tmp[N];
vector<int> g[N];
bool vst[N];
void dfs(int c, int p) {
  bool dp[N];
  fill(dp, dp + n + 1, false);
  dp[0] = true;
  tmp[c] = 1;
  for (int ch : g[c]) {
    if (ch != p) {
      dfs(ch, c);
      tmp[c] += tmp[ch];
      for (int i = n - 1; i >= 0; --i) {
        if (dp[i]) {
          dp[i + tmp[ch]] = true;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    dp[n - i - 1] |= dp[i];
  }
  for (int i = 1; i <= n; ++i) {
    vst[i] |= dp[i];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1), _i = (n - 1); i <= _i; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 1);
  int cnt = 0;
  for (int i = (1), _i = (n - 1 - 1); i <= _i; ++i) {
    if (vst[i]) {
      cnt += 1;
    }
  }
  printf("%d\n", cnt);
  for (int i = (1), _i = (n - 1 - 1); i <= _i; ++i) {
    if (vst[i]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
}
