#include <bits/stdc++.h>
using namespace std;
bool tmp[5000 + 10], ans[5000 + 10];
int n, sz, v[5000 + 10], cnt;
vector<int> g[5000 + 10];
void DFS(int v, int p) {
  cnt++;
  for (int j = 0; j < g[v].size(); j++)
    if (g[v][j] != p) DFS(g[v][j], v);
}
void work() {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    sz = 0;
    for (j = 0; j < g[i].size(); j++) {
      cnt = 0;
      DFS(g[i][j], i);
      v[sz++] = cnt;
    }
    tmp[0] = true;
    for (j = 1; j <= n; j++) tmp[j] = false;
    for (k = 0; k < sz; k++)
      for (j = n; j >= 0; j--)
        if (tmp[j]) tmp[j + v[k]] = true;
    for (k = 1; k <= n; k++) ans[k] = ans[k] || tmp[k];
  }
}
void read_data() {
  int j, x, y;
  cin >> n;
  for (j = 1; j < n; j++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
}
void write_data() {
  int k, res = 0;
  for (k = 1; k < n - 1; k++)
    if (ans[k]) res++;
  cout << res << endl;
  for (k = 1; k < n - 1; k++)
    if (ans[k]) cout << k << " " << n - 1 - k << endl;
}
int main() {
  read_data();
  work();
  write_data();
}
