#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const double eps = 1e-8;
const int iinf = INT_MAX;
const long long linf = 2e18;
const double dinf = 1e30;
const int MOD = 1000000007;
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
void print(int x) {
  cout << x << '\n';
  exit(0);
}
void PRINT(string x) {
  cout << x << '\n';
  exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int flag[N];
int dp[N][N];
int size[N];
vector<int> e[N];
int n;
void dfs(int now, int fat) {
  size[now] = 1;
  dp[now][0] = 1;
  for (int i = 0; i < ((int)e[now].size()); i++) {
    int to = e[now][i];
    if (to == fat) continue;
    dfs(to, now);
    size[now] += size[to];
    for (int i = n - 1; i >= 0; i--) dp[now][i + size[to]] |= dp[now][i];
  }
  for (int i = n - 1; i >= 0; i--) dp[now][i + n - size[now]] |= dp[now][i];
  for (int i = 1; i < n - 1; i++) flag[i] |= dp[now][i];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(1, -1);
  int ans = 0;
  for (int i = 1; i < n; i++)
    if (flag[i]) ans++;
  cout << ans << '\n';
  for (int i = 1; i < n - 1; i++)
    if (flag[i]) cout << i << " " << n - i - 1 << '\n';
  return 0;
}
