#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
long long n, m, a, b, c, k, temp, x, y;
const int MAXN = 100000 + 11;
void read(vector<long long> &v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
set<pair<long long, long long> > ans;
void printDistSum(int *arr, int &n) {
  int sum = 0;
  for (int i = 0; i < n; i++) sum += arr[i];
  bool dp[n + 1][sum + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= n; i++) dp[i][0] = true;
  for (int i = 1; i <= n; i++) {
    dp[i][arr[i - 1]] = true;
    for (int j = 1; j <= sum; j++) {
      if (dp[i - 1][j] == true) {
        dp[i][j] = true;
        dp[i][j + arr[i - 1]] = true;
      }
    }
  }
  for (int j = 1; j < sum; j++)
    if (dp[n][j] == true) {
      ans.insert({j, sum - j});
      ans.insert({sum - j, j});
    }
}
vector<long long> v[5001];
int sz[5001];
void dfs(int u, int p = -1) {
  sz[u] = 1;
  for (auto x : v[u]) {
    if (x == p) continue;
    dfs(x, u);
    sz[u] += sz[x];
  }
  int siz = v[u].size();
  int arr[siz];
  for (int i = 0; i < siz; i++)
    if (v[u][i] == p)
      arr[i] = n - sz[u];
    else
      arr[i] = sz[v[u][i]];
  printDistSum(arr, siz);
}
void solveforthiscase(const int &test) {
  cin >> n;
  m = n - 1;
  while (m--) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1);
  cout << ans.size();
  cout << '\n';
  for (auto x : ans) {
    cout << x.first << ' ' << x.second;
    cout << '\n';
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  for (int i = 1; i <= test; i++) {
    solveforthiscase(i);
  }
}
