#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5, INF = 2e9;
int n, ans;
set<pair<int, int> > s;
vector<int> a[MAXN];
int cnt[MAXN];
bool used[MAXN];
int can[MAXN], t;
void dfs(int x) {
  used[x] = true;
  vector<int> v;
  bool leaf = true;
  cnt[x]++;
  for (auto i : a[x]) {
    if (used[i]) {
      continue;
    }
    leaf = false;
    dfs(i);
    cnt[x] += cnt[i];
    v.push_back(cnt[i]);
  }
  if (leaf) {
    return;
  }
  t++;
  can[0] = t;
  v.push_back(n - cnt[x]);
  for (auto j : v) {
    for (int i = n - 1; i >= j; i--) {
      if (can[i - j] == t) {
        can[i] = t;
      }
    }
  }
  v.clear();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1);
  for (int i = 1; i < n - 1; i++) {
    if (can[i]) {
      s.insert(make_pair(i, n - i - 1));
      s.insert(make_pair(n - i - 1, i));
    }
  }
  cout << s.size() << '\n';
  for (auto i : s) {
    cout << i.first << ' ' << i.second << '\n';
  }
  return 0;
}
