#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int MAXN = (int)1e6 + 10;
int n;
vector<int> g[MAXN];
int sz[MAXN];
bool used[MAXN];
bool ok[MAXN];
bool kn[MAXN];
void dfs(int v, int p = 0) {
  sz[v] = 1;
  vector<int> all;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    sz[v] += sz[to];
    all.push_back(sz[to]);
  }
  all.push_back(n - sz[v]);
  kn[0] = 1;
  for (int w = 1; w <= n; w++) kn[w] = 0;
  for (auto it : all) {
    for (int w = n; w >= it; w--) {
      kn[w] |= kn[w - it];
    }
  }
  for (int w = 1; w <= n; w++) ok[w] |= kn[w];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ok[0] = 1;
  dfs(1);
  int all = 0;
  for (int i = 1; i < n - 1; i++)
    if (ok[i] || ok[n - i - 1]) all++;
  printf("%d\n", all);
  for (int i = 1; i < n - 1; i++) {
    if (ok[i] || ok[n - i - 1]) {
      printf("%d %d\n", i, n - i - 1);
    }
  }
  return 0;
}
