#include <bits/stdc++.h>
using namespace std;
bool comp(long long int a, long long int b) {
  if (a > b)
    return true;
  else
    return false;
}
int isP(long long int n) {
  if (n == 1) return 0;
  if (n == 2 || n == 3) return 1;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int t = power(a, b / 2);
  if (b % 2 == 1)
    return t * t * a;
  else
    return t * t;
}
long long int powMOD(long long int x, long long int y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long int t = powMOD(x, y / 2);
  if (y % 2 == 1)
    return t * t % 998244353 * x % 998244353;
  else
    return t * t % 998244353;
}
vector<long long int> g[5001];
long long int val[5001];
long long int val1[5001];
vector<long long int> ans;
map<long long int, bool> md;
vector<long long int> fun3(vector<long long int> v, long long int n) {
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += v[i];
  bool dp[n + 1][sum + 1];
  memset(dp, 0, sizeof(dp));
  for (long long int i = 0; i <= n; i++) dp[i][0] = 1;
  for (long long int i = 1; i <= n; i++) {
    dp[i][v[i - 1]] = 1;
    for (long long int j = 1; j <= sum; j++) {
      if (dp[i - 1][j] == 1) {
        dp[i][j] = 1;
        dp[i][j + v[i - 1]] = 1;
      }
    }
  }
  vector<long long int> ans;
  for (long long int j = 0; j <= sum; j++) {
    if (dp[n][j] == 1) ans.push_back(j);
  }
  return ans;
}
long long int fun(long long int u, long long int pa) {
  long long int cn = 0;
  for (long long int i = 0; i < g[u].size(); i++) {
    long long int v = g[u][i];
    if (v != pa) {
      cn += fun(v, u);
    }
  }
  cn += 1;
  return val[u] = cn;
}
void fun1(long long int u, long long int pa) {
  if (pa != -1) {
    val1[u] += val1[pa];
    val1[u] += val[pa] - val[u];
  }
  for (long long int i = 0; i < g[u].size(); i++) {
    long long int v = g[u][i];
    if (v != pa) fun1(v, u);
  }
}
void fun2(long long int u, long long int pa) {
  vector<long long int> ve;
  for (long long int i = 0; i < g[u].size(); i++) {
    long long int v = g[u][i];
    if (v != pa) {
      ve.push_back(val[v]);
    }
  }
  ve.push_back(val1[u]);
  vector<long long int> vv = fun3(ve, (long long int)ve.size());
  for (long long int i = 0; i < vv.size(); i++) {
    if (!md[vv[i]]) ans.push_back(vv[i]);
    md[vv[i]] = 1;
  }
  for (long long int i = 0; i < g[u].size(); i++) {
    long long int v = g[u][i];
    if (v != pa) {
      fun2(v, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    for (long long int i = 1; i < n; i++) {
      long long int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    fun(1, -1);
    fun1(1, -1);
    fun2(1, -1);
    vector<pair<long long int, long long int> > ans1;
    for (long long int i = 0; i < ans.size(); i++) {
      long long int val1 = ans[i];
      long long int val2 = n - 1 - ans[i];
      if (val1 >= 1 && val2 >= 1) ans1.push_back({val1, val2});
    }
    sort(ans1.begin(), ans1.end());
    cout << ans1.size() << "\n";
    for (long long int i = 0; i < ans1.size(); i++)
      cout << ans1[i].first << " " << ans1[i].second << "\n";
  }
  return 0;
}
