#include <bits/stdc++.h>
using namespace std;
const long N = 5010;
long n, num[N];
bool flag[N], dp[N][N];
vector<long> e[N];
void dfs(long fa, long son) {
  num[son] = 1;
  dp[son][0] = true;
  for (long i = 0; i < e[son].size(); i++) {
    long to = e[son][i];
    if (to == fa) continue;
    dfs(son, to);
    num[son] += num[to];
    for (long i = n - 1; i >= 0; i--)
      if (dp[son][i]) dp[son][i + num[to]] = true;
  }
  long n1 = n - num[son];
  for (long i = n - 1; i >= 0; i--)
    if (dp[son][i]) dp[son][i + n1] = true;
  for (long i = 1; i < n - 1; i++)
    if (dp[son][i]) flag[i] = true;
}
int main() {
  cin >> n;
  for (long i = 1; i <= (n - 1); i++) {
    long x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  memset(flag, false, sizeof(flag));
  memset(dp, false, sizeof(dp));
  dfs(0, 1);
  long ans = 0;
  for (long i = 1; i < n; i++)
    if (flag[i]) ans++;
  cout << ans << endl;
  for (long i = 1; i < n - 1; i++)
    if (flag[i]) cout << i << " " << n - i - 1 << endl;
}
