#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n;
vector<int> adj[N], a[N];
bool ok[N], can[N];
int nChild[N];
void DFS(int u, int dad) {
  int v;
  for (int i = 0; i < adj[u].size(); i++) {
    v = adj[u][i];
    if (v == dad) continue;
    DFS(v, u);
    nChild[u] += nChild[v] + 1;
    a[u].push_back(nChild[v] + 1);
  }
  a[u].push_back(n - nChild[u] - 1);
  memset(can, false, n);
  can[0] = true;
  for (int i = 0; i < a[u].size(); i++)
    for (int j = n - 2; j >= a[u][i]; j--) can[j] |= can[j - a[u][i]];
  for (int i = 1; i <= n - 1; i++) ok[i] |= can[i];
}
int main() {
  cin >> n;
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(1, 0);
  int res = 0;
  for (int i = 1; i < n - 1; i++)
    if (ok[i]) res++;
  cout << res << endl;
  for (int i = 1; i < n - 1; i++)
    if (ok[i]) printf("%d %d\n", i, n - 1 - i);
  return 0;
}
