#include <bits/stdc++.h>
using namespace std;
vector<int> edge[5555];
vector<int> pick[5555];
int n;
int Size[5555] = {0};
int F[5555];
void dfs(int v, int f) {
  int dp[5555] = {0};
  Size[v] = 1;
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == f) continue;
    dfs(edge[v][i], v);
    if (Size[edge[v][i]] > 0 && Size[edge[v][i]] < n - 1)
      pick[v].push_back(Size[edge[v][i]]);
    Size[v] += Size[edge[v][i]];
  }
  if (n - Size[v] > 0 && n - Size[v] < n - 1) pick[v].push_back(n - Size[v]);
  dp[0] = 1;
  for (int i = pick[v].size() - 1; i >= 0; i--)
    for (int j = n; j >= pick[v][i]; j--)
      if (dp[j - pick[v][i]]) dp[j] = 1;
  for (int i = 1; i < n; i++)
    if (dp[i]) F[i] = 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) edge[i].clear(), pick[i].clear();
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs(1, -1);
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
    if (F[i]) ans++;
  printf("%d\n", ans);
  for (int i = 1; i < n - 1; i++)
    if (F[i]) printf("%d %d\n", i, n - 1 - i);
}
