#include <bits/stdc++.h>
using namespace std;
const int N = 5002;
int n, childs[N];
vector<vector<int> > g(N);
bool dp[N], valid[N];
int dfs(int i, int p) {
  childs[i] = 1;
  for (int j : g[i])
    if (j != p) childs[i] += dfs(j, i);
  return childs[i];
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 1);
  for (int i = (1); i <= (int)(n); ++i) {
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for (int j : g[i])
      if (childs[j] < childs[i])
        for (int k = (n - 1 - childs[j]); k >= (int)(0); --k)
          if (dp[k]) dp[k + childs[j]] = 1;
    for (int k = (childs[i] - 1); k >= (int)(0); --k)
      if (dp[k]) dp[k + n - childs[i]] = 1;
    for (int j = (1); j <= (int)(n - 2); ++j)
      if (dp[j]) valid[j] = 1;
  }
  vector<int> ans;
  for (int j = (1); j <= (int)(n - 2); ++j)
    if (valid[j]) ans.push_back(j);
  cout << (((int)(ans).size())) << endl;
  for (int i : ans) printf("%d %d\n", i, n - 1 - i);
}
