#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
int n, down[MAXN];
vector<pair<long long, long long> > ans;
vector<int> c[MAXN], G[MAXN];
bool b[MAXN];
void dfs(int u, int p) {
  down[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    dfs(v, u);
    down[u] += down[v];
    c[u].push_back(down[v]);
  }
  if (p != -1) c[u].push_back(n - down[u]);
  memset(b, 0, sizeof b);
  b[0] = true;
  for (int i = 0; i < c[u].size(); i++) {
    int x = c[u][i];
    for (int j = MAXN - 1; j > 0; j--)
      if (j - x >= 0) b[j] |= b[j - x];
  }
  for (int i = 1; i < n - 1; i++)
    if (b[i]) ans.push_back(pair<long long, long long>(i, n - 1 - i));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0, -1);
  sort(ans.begin(), ans.end());
  int sz = unique(ans.begin(), ans.end()) - ans.begin();
  cout << sz << endl;
  for (int i = 0; i < sz; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
