#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, sz[N];
bool dp[N][N], ans[N];
vector<int> g[N];
void dfs(int v, int pr = -1) {
  dp[v][0] = true;
  sz[v] = 1;
  for (int to : g[v]) {
    if (to != pr) {
      dfs(to, v);
      sz[v] += sz[to];
      for (int j = n; j - sz[to] >= 0; j--) {
        if (dp[v][j - sz[to]]) {
          dp[v][j] = true;
        }
      }
    }
  }
  int val = n - sz[v];
  for (int j = n; j - val >= 0; j--) {
    if (dp[v][j - val]) {
      dp[v][j] = true;
    }
  }
  for (int i = 1; n - i - 1 > 0; i++) {
    if (dp[v][i] && dp[v][n - i - 1]) {
      ans[i] = true;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  int cur = 0;
  for (int i = 1; i < n; i++) {
    if (ans[i]) {
      cur++;
    }
  }
  cout << cur << "\n";
  for (int i = 1; i < n; i++) {
    if (ans[i]) {
      cout << i << " " << n - i - 1 << "\n";
    }
  }
}
