#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int64_t mod1 = 1e9 + 6;
int64_t power(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
  else
    return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
           mod;
}
int64_t n;
vector<int64_t> v[5001];
int64_t sz[5001];
int64_t par[5001];
void dfs(int64_t u, int64_t pari) {
  sz[u] = 1;
  for (int64_t i = 0; i < v[u].size(); ++i) {
    if (v[u][i] == pari) continue;
    par[v[u][i]] = u;
    dfs(v[u][i], u);
    sz[u] += sz[v[u][i]];
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int64_t i = 1; i <= n - 1; ++i) {
    int64_t x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  par[1] = 0;
  dfs(1, 0);
  vector<int64_t> we[n + 1];
  for (int64_t i = 1; i <= n; ++i) {
    for (int64_t j = 0; j < v[i].size(); ++j) {
      if (v[i][j] != par[i]) we[i].push_back(sz[v[i][j]]);
    }
    we[i].push_back(sz[1] - sz[i]);
  }
  int64_t dp[n + 1];
  memset(dp, 0, sizeof(dp));
  for (int64_t i = 1; i <= n; ++i) {
    int64_t x[n + 1];
    memset(x, 0, sizeof(x));
    for (int64_t k = 0; k < we[i].size(); ++k) {
      for (int64_t j = n; j >= 1; --j) {
        if (x[j] == 1 && j + we[i][k] <= n) x[j + we[i][k]] = 1;
      }
      x[we[i][k]] = 1;
    }
    for (int64_t j = 1; j <= n; ++j) dp[j] = max(dp[j], x[j]);
  }
  vector<pair<int64_t, int64_t>> ans;
  for (int64_t i = 1; i <= n - 2; ++i) {
    if (dp[i]) {
      ans.push_back({i, n - i - 1});
    }
  }
  cout << ans.size() << '\n';
  for (int64_t i = 0; i < ans.size(); ++i)
    cout << ans[i].first << " " << ans[i].second << '\n';
}
