#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 2;
vector<int> g[N];
int cnt[N];
int parent[N];
void cnt_dfs(int v, int par = -1) {
  cnt[v] = 1;
  parent[v] = par;
  for (int to : g[v]) {
    if (to == par) continue;
    cnt_dfs(to, v);
    cnt[v] += cnt[to];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  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);
  }
  cnt_dfs(1);
  char finaldp[N];
  fill(finaldp, finaldp + N, 0);
  char dp[N];
  int have[N];
  int hsz = 0;
  for (int v = 1; v <= n; ++v) {
    fill(dp, dp + N, 0);
    dp[0] = 1;
    vector<int> sizes;
    hsz = 1;
    have[0] = 0;
    if (n - cnt[v]) sizes.push_back(n - cnt[v]);
    for (int to : g[v]) {
      if (to == parent[v]) continue;
      sizes.push_back(cnt[to]);
    }
    for (int x : sizes) {
      int oldsz = hsz;
      for (int i = 0; i < oldsz; ++i) {
        int cur = have[i];
        if (!dp[cur + x]) {
          dp[cur + x] = 1;
          have[hsz++] = cur + x;
        }
      }
    }
    for (int i = 0; i < N; ++i) finaldp[i] |= dp[i];
  }
  finaldp[0] = finaldp[n - 1] = 0;
  set<pair<int, int> > ans;
  for (int i = 0; i < n; ++i) {
    if (!finaldp[i]) continue;
    ans.insert(make_pair(i, n - 1 - i));
  }
  cout << ans.size() << "\n";
  for (pair<int, int> entry : ans) {
    cout << entry.first << " " << entry.second << "\n";
  }
}
