#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500005;
vector<int> e[Maxn];
int sz[Maxn], n, a, b;
int cnt, ans1[Maxn], ans2[Maxn];
bitset<5010> tmp, ans;
void dfs(int x, int fa) {
  sz[x] = 1;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) {
      dfs(e[x][i], x);
      sz[x] += sz[e[x][i]];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  if (n <= 2) return puts("0") * 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    tmp.reset();
    tmp.set(0);
    for (int j = 0; j < e[i].size(); j++)
      if (sz[e[i][j]] > sz[i])
        tmp |= (tmp << (n - sz[i]));
      else
        tmp |= (tmp << sz[e[i][j]]);
    ans |= tmp;
  }
  for (int i = 1; i < n - 1; i++)
    if (ans[i] == 1) {
      cnt++;
      ans1[cnt] = i;
      ans2[cnt] = n - i - 1;
    }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", ans1[i], ans2[i]);
}
