#include <bits/stdc++.h>
using namespace std;
vector<int> graph[5001];
bool subset[5001][5001];
set<pair<int, int>> ans_pairs;
vector<int> child_nodes(5001, -1);
int total_nodes;
void insert_into_answer(int network1, int network2) {
  if (network1 != 0 && network2 != 0) {
    ans_pairs.insert({network1, network2});
    ans_pairs.insert({network2, network1});
  }
  return;
}
bool isSubsetSum(vector<int> &set, int n, int sum) {
  for (int i = 0; i <= set.size(); i++) subset[i][0] = true;
  for (int j = 1; j <= sum; j++) subset[0][j] = false;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      if (j < set[i - 1]) subset[i][j] = subset[i - 1][j];
      if (j >= set[i - 1])
        subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]];
    }
  }
  return subset[n][sum];
}
int dfs(int id, int parent) {
  if (child_nodes[id] != -1) {
    return child_nodes[id];
  }
  if (graph[id].size() == 0) {
    return child_nodes[id] = 1;
  }
  int temp = 0;
  for (long long i = 0; i < graph[id].size(); i++) {
    if (graph[id][i] != parent) {
      temp += dfs(graph[id][i], id);
    }
  }
  return child_nodes[id] = temp + 1;
}
void solve(int id, int parent) {
  insert_into_answer(child_nodes[id] - 1, total_nodes - child_nodes[id]);
  vector<int> childs_to_adjacent;
  for (long long i = 0; i < graph[id].size(); i++) {
    if (graph[id][i] != parent) {
      childs_to_adjacent.push_back(child_nodes[graph[id][i]]);
    }
  }
  isSubsetSum(childs_to_adjacent, childs_to_adjacent.size(), child_nodes[id]);
  int child_length = childs_to_adjacent.size();
  for (long long i = 1; i < child_nodes[id]; i++) {
    if (subset[child_length][i]) {
      insert_into_answer(i, total_nodes - i - 1);
    }
  }
  for (long long i = 0; i < graph[id].size(); i++) {
    if (graph[id][i] != parent) {
      solve(graph[id][i], id);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> total_nodes;
  int x, y;
  for (long long i = 1; i < total_nodes; i++) {
    cin >> x >> y;
    graph[x - 1].push_back(y - 1);
    graph[y - 1].push_back(x - 1);
  }
  int a = dfs(0, -1);
  solve(0, -1);
  cout << ans_pairs.size() << endl;
  for (auto it : ans_pairs) {
    cout << it.first << " " << it.second << endl;
  }
  return 0;
}
