#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[5005];
bitset<50005> ans;
int dfs(int node, int from) {
  int children = 1;
  bitset<50005> d;
  d[0] = 1;
  for (int x : G[node]) {
    if (x != from) {
      int ch = dfs(x, node);
      children += ch;
      d |= (d << ch);
    }
  }
  if (children > 1) {
    d |= (d << (n - children));
    ans |= d;
  }
  return children;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1, 0);
  int cnt = 0;
  for (int i = 1; i <= n - 2; i++) cnt += ans[i];
  cout << cnt << '\n';
  for (int i = 1; i <= n - 2; i++) {
    if (ans[i]) {
      cout << i << ' ' << n - i - 1 << '\n';
    }
  }
}
