#include <bits/stdc++.h>
using namespace std;
const int maxn = 5105;
const int INF = 0x3f3f3f3f;
vector<int> G[maxn];
int n;
int num[maxn];
bool dp[maxn][maxn];
bool flag[maxn];
void dfs(int u, int fa) {
  num[u] = 1;
  dp[u][0] = 1;
  int sz = G[u].size();
  for (int i = 0; i < sz; i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
    num[u] += num[v];
    for (int i = n - 1; i >= 0; i--) {
      if (dp[u][i]) dp[u][i + num[v]] = 1;
    }
  }
  int fanum = n - num[u];
  for (int i = n - 1; i >= 0; i--) {
    if (dp[u][i]) dp[u][i + fanum] = 1;
  }
  for (int i = 1; i < n - 1; i++) {
    if (dp[u][i]) flag[i] = true;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) G[i].clear();
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  memset(dp, 0, sizeof(dp));
  memset(flag, 0, sizeof(flag));
  dfs(1, -1);
  int ans = 0;
  for (int i = 1; i < n; i++)
    if (flag[i]) ans++;
  printf("%d\n", ans);
  for (int i = 1; i < n - 1; i++) {
    if (flag[i]) printf("%d %d\n", i, n - i - 1);
  }
}
