#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > adjList;
bool dp[5000][5000];
int cnt[5000];
bool taken[5001];
vector<pair<int, int> > reset;
int solve(int node, int ind, int sum) {
  if (ind == adjList[node].size()) {
    if (sum > n - 1 - sum) sum = n - 1 - sum;
    taken[sum] = taken[n - 1 - sum] = true;
    return true;
  }
  if (dp[ind][sum]) return true;
  reset.push_back(make_pair(ind, sum));
  solve(node, ind + 1, sum);
  solve(node, ind + 1, sum + cnt[ind]);
  return dp[ind][sum] = true;
}
int dfs(int node, int parent) {
  int maxi = 1;
  for (int i = 0; i < adjList[node].size(); i++) {
    int ch = adjList[node][i];
    if (ch != parent) {
      maxi += dfs(ch, node);
    }
  }
  return maxi;
}
int main() {
  scanf("%d", &n);
  adjList.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    adjList[x].push_back(y);
    adjList[y].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    if (adjList[i].size() == 1) continue;
    for (int j = 0; j < adjList[i].size(); j++) cnt[j] = dfs(adjList[i][j], i);
    for (int j = 0; j < reset.size(); j++)
      dp[reset[j].first][reset[j].second] = false;
    reset.clear();
    solve(i, 0, 0);
  }
  vector<pair<int, int> > ans;
  for (int i = 1; i < n - 1; i++) {
    if (taken[i])
      if (n - i - 1 == i)
        ans.push_back(make_pair(i, i));
      else
        ans.push_back(make_pair(i, n - 1 - i));
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
