#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
vector<int> ne[maxn];
int cnt[maxn], n;
int dp[maxn], res[maxn];
void dfs(int v, int prev = -1) {
  cnt[v] = 1;
  vector<int> w;
  int last = n - 1;
  for (int i = 0; i < (int)ne[v].size(); i++) {
    int u = ne[v][i];
    if (u != prev) {
      dfs(u, v);
      cnt[v] += cnt[u];
      w.push_back(cnt[u]);
      last -= cnt[u];
    }
  }
  if (last > 0) {
    w.push_back(last);
  }
  fill(dp, dp + n, 0);
  dp[0] = 1;
  for (int i = 0, sum = 0; i < (int)w.size(); sum += w[i], i++) {
    for (int s = sum; s >= 0; s--) {
      if (dp[s]) {
        dp[s + w[i]] = 1;
      }
    }
  }
  for (int i = 1; i + 1 < n; i++) {
    res[i] |= dp[i];
  }
}
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    ne[a].push_back(b);
    ne[b].push_back(a);
  }
  dfs(1);
  int res_n = 0;
  for (int i = 1; i + 1 < n; i++) {
    res_n += res[i];
  }
  printf("%d\n", res_n);
  for (int i = 1; i + 1 < n; i++) {
    if (res[i]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
  return 0;
}
