#include <bits/stdc++.h>
using namespace std;
bitset<5005> ans;
int n;
vector<int> E[5005];
int sz[5005];
inline void dfs(int u, int fa) {
  if (sz[u]) return;
  sz[u] = 1;
  bitset<5005> tmp;
  tmp = 1;
  for (int i = 0; i < E[u].size(); ++i) {
    int v = E[u][i];
    dfs(v, u);
    if (v != fa) sz[u] += sz[v], tmp |= tmp << sz[v];
  }
  tmp |= tmp << (n - sz[u]);
  ans |= tmp;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int ref = 0; ref < n - 1; ++ref) {
    int x, y;
    cin >> x >> y;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  dfs(1, 0);
  int cnt = 0;
  for (int i = 1; i <= n - 2; ++i) {
    if (ans[i]) ++cnt;
  }
  cout << cnt << endl;
  for (int i = 1; i <= n - 2; ++i) {
    if (ans[i]) cout << i << " " << n - i - 1 << endl;
  }
  return 0;
}
