#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int M = 1e9 + 7;
vector<int> graph[N];
int subtree[N];
bool visited[N];
int n;
bool dp[N];
set<pair<int, int> > ans;
void final(vector<int> vi, int v) {
  memset(dp, false, sizeof(dp));
  dp[0] = true;
  for (auto x : vi) {
    for (int i = N - 1; i >= 0; i--) {
      if (dp[i] && i + x < N) dp[i + x] = true;
    }
  }
  for (int i = 0; i < subtree[v]; i++) {
    if (dp[i]) {
      int x = n - subtree[v];
      if ((i + x) && (subtree[v] - 1 - i))
        ans.insert(make_pair(i + x, subtree[v] - 1 - i));
      if ((i) && (subtree[v] - 1 - i + x))
        ans.insert(make_pair(i, subtree[v] - 1 - i + x));
    }
  }
}
void dfs(int v) {
  visited[v] = true;
  vector<int> vi;
  for (auto i : graph[v]) {
    if (!visited[i]) {
      dfs(i);
      vi.push_back(subtree[i]);
      subtree[v] += subtree[i];
    }
  }
  final(vi, v);
  return;
}
void solve() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) subtree[i] = 1;
  dfs(1);
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it.first << " " << it.second << "\n";
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
