#include <bits/stdc++.h>
using namespace std;
bitset<5001> ans, tmp;
vector<int> adj[5001];
vector<int> cl[5001];
int cn[5001] = {0};
void dfs(int u, int p) {
  for (auto v : adj[u]) {
    if (v != p) {
      dfs(v, u);
      cl[u].push_back(cn[v] + 1);
      cn[u] += cn[v] + 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(0, -1);
  for (int i = 1; i < n; i++) {
    cl[i].push_back(n - 1 - cn[i]);
  }
  for (int i = 0; i < n; i++) {
    tmp = 1;
    for (auto v : cl[i]) {
      tmp |= tmp << v;
    }
    ans |= tmp;
  }
  cout << (ans.count() - ans[0] - ans[n - 1]) << "\n";
  for (int i = 1; i < n - 1; i++) {
    if (ans[i]) {
      cout << i << " " << n - 1 - i << "\n";
    }
  }
  return 0;
}
