#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 300 * 1000 + 7;
const long long MOD = 998244353;
const double PI = 2 * acos(0.0);
long long n;
vector<long long> adj[5050];
long long sz[5050];
bool ans[5050], temp[5050];
long long tot = 0;
void dfs(long long cur, long long par) {
  long long num_Bro = adj[cur].size();
  sz[cur] = 1;
  for (long long i0 = 0; i0 < num_Bro; i0++) {
    long long bro = adj[cur][i0];
    if (bro == par) continue;
    dfs(bro, cur);
    sz[cur] += sz[bro];
  }
  return;
}
void dfs1(long long cur, long long par) {
  long long num_Bro = adj[cur].size();
  vector<long long> kobe;
  for (long long i0 = 0; i0 < num_Bro; i0++) {
    long long bro = adj[cur][i0];
    if (bro == par) {
      kobe.push_back(n - sz[cur]);
      continue;
    }
    dfs1(bro, cur);
    kobe.push_back(sz[bro]);
  }
  long long SIZE = kobe.size();
  for (long long i0 = 0; i0 <= n; i0++) temp[i0] = false;
  temp[0] = true;
  for (long long i0 = 0; i0 < SIZE; i0++) {
    long long james = kobe[i0];
    for (long long k = n - 2; k >= james; k--)
      if (temp[k - james]) temp[k] = true;
  }
  for (long long i0 = 1; i0 <= n - 2; i0++) {
    if (temp[i0]) {
      ans[i0] = true;
    }
  }
  return;
}
int main(void) {
  cin >> n;
  for (long long i0 = 0; i0 < n - 1; i0++) {
    long long i, j;
    cin >> i >> j;
    adj[i].push_back(j);
    adj[j].push_back(i);
  }
  dfs(1, 1);
  dfs1(1, 1);
  for (long long i0 = 1; i0 <= n - 2; i0++) {
    if (ans[i0] || ans[n - 1 - i0]) tot++;
  }
  cout << tot << endl;
  for (long long i0 = 1; i0 <= n - 2; i0++) {
    if (ans[i0] || ans[n - 1 - i0]) {
      cout << i0 << " " << n - 1 - i0 << endl;
    }
  }
  return 0;
}
