#include <bits/stdc++.h>
using namespace std;
vector<int> G[5005];
bool dp[5005][5005];
int sz[5005];
int n;
inline void update_dp(int u, int val) {
  for (int i = n - 1; i >= 0; --i) {
    if (dp[u][i]) dp[u][i + val] = 1;
  }
}
void dfs(int u, int father) {
  sz[u] = 1;
  dp[u][0] = 1;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == father) continue;
    dfs(v, u);
    sz[u] += sz[v];
    update_dp(u, sz[v]);
  }
  update_dp(u, n - sz[u]);
}
bool vis[5005];
int main() {
  scanf("%d", &n);
  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);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < n - 1; ++j) {
      if (dp[i][j]) {
        vis[j] = true;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (vis[i]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
  return 0;
}
