#include <bits/stdc++.h>
const int N = 5e5 + 10;
using namespace std;
vector<int> G[N];
int sum[N], tot, f[N], v[N];
int dfs(int u, int father, int tot) {
  sum[tot]++;
  for (int i = 0; i < G[u].size(); i++) {
    int j = G[u][i];
    if (j == father) continue;
    dfs(j, u, (father == -1 ? ++tot : tot));
  }
  return tot;
}
int main() {
  int n, a, b, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    memset(sum, 0, sizeof sum);
    memset(f, 0, sizeof f);
    f[0] = 1;
    int tot = dfs(i, -1, 0);
    for (int j = 1; j <= tot; j++) {
      for (int k = 5000; k >= sum[j]; k--) {
        f[k] = max(f[k], f[k - sum[j]]);
      }
    }
    if (tot == 1) continue;
    f[n - 1] = 0;
    ans = 0;
    for (int j = 5000; j >= 1; j--) {
      v[j] = max(v[j], f[j]);
      ans += v[j];
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i < 5000; i++) {
    if (v[i]) printf("%d %d\n", i, n - i - 1);
  }
  return 0;
}
