#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
const int N = 5005;
vector<int> v[N];
bool poss[N], local[N];
int n;
int dfs(int z, int p) {
  int s = 1;
  vector<int> sizes;
  for (int x : v[z]) {
    if (x == p) continue;
    int temp = dfs(x, z);
    s += temp;
    sizes.push_back(temp);
  }
  if (sizes.size() > 0) {
    if (p != 0) sizes.push_back(n - s);
    for (int i = 1; i < (int)(n + 1); ++i) local[i] = 0;
    local[0] = 1;
    for (int x : sizes) {
      for (int i = n - x; i >= 0; i--) {
        if (local[i] == 1) local[x + i] = 1, poss[i + x] = 1;
      }
    }
  }
  return s;
}
void solve() {
  cin >> n;
  for (int i = 1; i < (int)(n); ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  vector<int> ans;
  for (int i = 1; i <= n - 2; i++) {
    if (poss[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i : ans) cout << i << " " << n - 1 - i << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
