#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
unsigned long long MOD = int(1e9 + 7);
int n;
int sz[(int)(5e3 + 5)], a[(int)(5e3 + 5)], first[(int)(5e3 + 5)],
    o[(int)(5e3 + 5)];
vector<int> g[(int)(5e3 + 5)];
vector<int> ans;
set<pair<int, int> > pts;
void dfs(int v, int p) {
  sz[v] = 1;
  vector<int> cmp;
  for (int u : g[v]) {
    if (u == p) continue;
    dfs(u, v);
    sz[v] += sz[u];
    cmp.push_back(sz[u]);
  }
  cmp.push_back(n - sz[v]);
  memset(first, 0, sizeof(first));
  first[0] = 1;
  for (int size : cmp) {
    for (int j = n - size; j >= 0; j--)
      if (first[j]) first[j + size] = 1;
  }
  for (int i = 0; i <= n; i++)
    if (first[i]) o[i] = 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  memset(sz, 0, sizeof(sz));
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  memset(o, 0, sizeof(o));
  dfs(1, 0);
  int size = 0;
  for (int i = 1; i < n - 1; i++)
    if (o[i]) ans.push_back(i);
  cout << ans.size() << endl;
  for (int x : ans) {
    cout << x << " " << n - 1 - x << endl;
  }
  return 0;
}
