#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int N;
vector<int> adj[MAXN], ch[MAXN];
bool ans[MAXN];
bool dp[MAXN];
int cnt[MAXN];
int dfs(int n, int p) {
  int ret = 1;
  for (int i = 0, _i = adj[n].size(); i < _i; ++i) {
    if (adj[n][i] == p) continue;
    ch[n].push_back(adj[n][i]);
    ret += dfs(adj[n][i], n);
  }
  return cnt[n] = ret;
}
void aux(int a) {
  for (int i = (N - a), _i = (0); i >= _i; --i) {
    dp[i + a] |= dp[i];
  }
}
void solve(int n) {
  memset(dp, 0, sizeof dp);
  dp[0] = 1;
  for (int i = 0, _i = ch[n].size(); i < _i; ++i) {
    aux(cnt[ch[n][i]]);
  }
  aux(N - cnt[n]);
  for (int i = 0, _i = N; i <= _i; ++i) ans[i] |= dp[i];
}
int main(int argc, char *argv[]) {
  scanf("%d", &N);
  for (int i = 0, _i = N - 1; i < _i; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  for (int i = 0, _i = N; i <= _i; ++i) solve(i);
  int ansc = 0;
  for (int i = (1), _i = (N - 2); i <= _i; ++i) ansc += ans[i];
  printf("%d\n", ansc);
  for (int i = (1), _i = (N - 2); i <= _i; ++i) {
    if (ans[i]) {
      printf("%d %d\n", i, N - 1 - i);
    }
  }
  return 0;
}
