#include <bits/stdc++.h>
using namespace std;
int n, d[5555], color[5555], ans[5555];
vector<int> g[5555];
int c, m;
void dfs(int u, int cl) {
  color[u] = cl;
  c++;
  for (typeof((g[u]).begin()) i = (g[u]).begin(); i != (g[u]).end(); i++)
    if (color[*i] != cl) dfs(*i, cl);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  d[0] = 1;
  for (int i = (1); i <= (n); i++)
    if (g[i].size() > 1) {
      color[i] = i;
      m = 0;
      for (int u = 1; u <= n; d[u] = 0, u++)
        ;
      for (typeof((g[i]).begin()) j = (g[i]).begin(); j != (g[i]).end(); j++) {
        c = 0;
        dfs(*j, i);
        for (int k = m; k >= 0; k--)
          if (d[k]) {
            d[k + c] = 1;
            m = min(max(m, k + c), n);
          }
      }
      for (int j = (1); j <= (n); j++)
        if (d[j]) ans[j] = 1;
    }
  int res = 0;
  for (int i = (1); i <= (n - 2); i++) res += ans[i];
  printf("%d\n", res);
  for (int i = (1); i <= (n - 2); i++)
    if (ans[i]) printf("%d %d\n", i, n - 1 - i);
}
