#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> par;
vector<int> sub;
vector<bool> dp;
vector<bool> dp2;
void dfs(int v, int p = -1) {
  visited[v] = true;
  for (int u : adj[v]) {
    if (!visited[u]) {
      par[u] = v;
      dfs(u, v);
    }
    if (u != p) sub[v] += sub[u];
  }
}
int solve() {
  int n;
  cin >> n;
  adj.resize(n + 1);
  sub.resize(n + 1);
  par.resize(n + 1);
  for (int i = (1); i < (n + 1); i++) sub[i] = 1;
  visited.resize(n + 1);
  for (int i = (1); i < (n); i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int root = -1;
  for (int i = (1); i < (n + 1); i++) {
    if ((long long)(adj[i]).size() == 1) {
      root = i;
      break;
    }
  }
  assert(root != -1);
  par[root] = -1;
  dfs(root);
  set<pair<int, int>> ans;
  for (int i = (1); i < (n + 1); i++) {
    if ((long long)(adj[i]).size() != 1) {
      set<int> temp;
      dp2.clear();
      dp2.resize(5005);
      for (int u : adj[i]) {
        int y = sub[u];
        if (u == par[i]) {
          y = n - sub[i];
        }
        if (!temp.empty()) {
          dp.clear();
          dp.resize(5005);
          set<int> tem;
          for (auto it = temp.begin(); it != temp.end(); it++) {
            if (!dp[y + *it]) {
              dp[y + *it] = true;
              tem.insert(y + *it);
            }
          }
          for (auto it = tem.begin(); it != tem.end(); it++) {
            if (!dp2[*it]) {
              dp2[*it] = true;
              temp.insert(*it);
            }
          }
        }
        temp.insert(y);
      }
      for (auto it = temp.begin(); it != temp.end(); it++) {
        ans.insert({*it, n - 1 - *it});
        ans.insert({n - 1 - *it, *it});
      }
    }
  }
  cout << (long long)(ans).size() - 2 << '\n';
  for (auto it = ans.begin(); it != ans.end(); it++) {
    if (!(it->first == 0 || it->first == n - 1))
      cout << it->first << " " << it->second << '\n';
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t) {
    solve();
    t--;
  }
  return 0;
}
