#include <bits/stdc++.h>
using namespace std;
int n;
int sz[5005];
bool dp[5005][5005];
bool ans[5005];
vector<int> from[5005];
void dfs(int x, int last) {
  int i, j, y;
  sz[x] = 1;
  dp[x][0] = 1;
  for (i = 0; i < from[x].size(); i++) {
    y = from[x][i];
    if (y == last) continue;
    dfs(y, x);
    sz[x] += sz[y];
    for (j = n; j >= 0; j--)
      if (dp[x][j]) dp[x][j + sz[y]] = 1;
  }
  for (i = 1; i < n; i++) ans[i] |= dp[x][i] | dp[x][n - 1 - i];
}
int main() {
  int i, x, y, cnt;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &x, &y);
    from[x].push_back(y);
    from[y].push_back(x);
  }
  dfs(1, 0);
  cnt = 0;
  for (i = 1; i < n - 1; i++)
    if (ans[i]) cnt++;
  printf("%d\n", cnt);
  for (i = 1; i < n - 1; i++)
    if (ans[i]) printf("%d %d\n", i, n - 1 - i);
}
