#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<int> adj[300010], val(300010, 1), vis(300010, 0), dis1(300010, 0),
    dis2(300010, 0);
int myrandom(int i) { return std::rand() % i; }
int dp[5010];
int n;
set<pair<int, int>> st;
int maxi = 0;
int poss[5010][5010];
void dfs(int a) {
  vis[a] = 1;
  int cnt = 0;
  vector<int> v;
  for (auto i : adj[a]) {
    if (vis[i] == 0) {
      dfs(i);
      if (dp[i] > 0) {
        v.push_back(dp[i]);
      }
      cnt = cnt + dp[i];
    }
  }
  int cnt1 = n - cnt - 1;
  if (cnt1 > 0) {
    v.push_back(cnt1);
  }
  int n = (int)v.size();
  int sum = accumulate((v).begin(), (v).end(), 0);
  int res[sum + 1];
  memset(res, 0, sizeof(res));
  res[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = sum; j >= 0; j--) {
      if (j - v[i] >= 0) {
        res[j] = res[j] | res[j - v[i]];
      }
    }
  }
  maxi = max(maxi, sum);
  for (int i = 1; i < sum; i++) {
    poss[i][sum - i] = poss[i][sum - i] | res[i];
  }
  dp[a] = 1 + cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(poss, 0, sizeof(poss));
  dfs(1);
  vector<pair<int, int>> ans;
  for (int i = 1; i <= 5000; i++) {
    for (int j = 1; j <= 5000; j++) {
      if (i + j == maxi && poss[i][j] == 1) {
        ans.push_back({i, j});
      }
    }
  }
  cout << (int)ans.size() << '\n';
  for (auto i : ans) {
    cout << i.first << " " << i.second << '\n';
  }
}
