#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 5;
const int M = 60005;
const int inf = 1e9;
const long long INF = (long long)(1e18);
void solve() {}
int n;
vector<int> G[5005];
int dp[5005];
int parent[5005];
set<int> st;
void dfs(int v, int par) {
  parent[v] = par;
  if (G[v].size() == 1) {
    dp[v] = 0;
    return;
  }
  for (auto to : G[v]) {
    if (to == par) continue;
    dfs(to, v);
    dp[v] += dp[to] + 1;
  }
}
void knapSack(vector<int> a) {
  sort(a.begin() + 1, a.end());
  vector<vector<bool>> DP;
  DP.resize(a.size());
  for (int i = 0; i < DP.size(); i++) {
    DP[i].resize(n - 1, false);
  }
  for (int i = 0; i < DP.size(); i++) DP[i][0] = true;
  for (int i = 1; i < a.size(); i++) {
    int cur = a[i];
    for (int j = 1; j <= n - 2; j++) {
      if (j - cur >= 0 && DP[i - 1][j - cur]) DP[i][j] = true;
      if (DP[i - 1][j]) DP[i][j] = DP[i - 1][j];
    }
  }
  for (int i = 1; i <= n - 2; i++) {
    if (DP[a.size() - 1][i]) st.insert(i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int root = 1;
  while (G[root].size() == 1) root++;
  dfs(root, -1);
  for (int v = 1; v <= n; v++) {
    vector<int> a;
    a.push_back(-1);
    int sum = 0;
    for (auto to : G[v]) {
      if (to == parent[v]) continue;
      a.push_back(dp[to] + 1);
      sum += dp[to] + 1;
    }
    a.push_back(n - sum - 1);
    knapSack(a);
  }
  int ans = 0;
  vector<pair<int, int>> res;
  for (auto x : st) {
    if (st.find(n - 1 - x) != st.end()) {
      ans++;
      res.push_back({x, n - 1 - x});
    }
  }
  sort(res.begin(), res.end());
  cout << ans << "\n";
  for (auto pi : res) cout << pi.first << " " << pi.second << "\n";
  return 0;
}
