#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
const int inf = 1 << 29;
const int mod = 1000000007;
const double eps = 1e-8;
vector<int> v[maxn];
vector<pair<int, int> > out;
int n, siz[maxn];
void dfs(int x, int p) {
  siz[x] = 1;
  int si;
  if (p != -1 && v[x].size() <= 1) return;
  bool dp[maxn] = {0};
  dp[0] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int toit = v[x][i];
    if (toit != p) {
      dfs(toit, x);
      si = siz[toit];
      siz[x] += si;
      for (int j = n; j >= si; j--)
        if (dp[j - si]) dp[j] = 1;
    }
  }
  si = n + 1 - siz[x];
  for (int i = n; i >= si; i--)
    if (dp[i - si]) dp[i] = 1;
  for (int i = 1; i < n; i++)
    if (dp[i]) out.push_back(make_pair(i, n - i));
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  n--;
  dfs(1, -1);
  sort(out.begin(), out.end());
  out.erase(unique(out.begin(), out.end()), out.end());
  printf("%lu\n", out.size());
  for (int i = 0; i < out.size(); i++)
    printf("%d %d\n", out[i].first, out[i].second);
}
