#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, sz[N], ans[N], dp[N][N];
vector<int> G[N];
void dfs(int u, int p) {
  sz[u] = 1;
  dp[u][0] = 1;
  for (auto v : G[u])
    if (v != p) {
      dfs(v, u);
      for (int i = n - 1; i >= 0; --i)
        if (dp[u][i]) dp[u][i + sz[v]] = 1;
      sz[u] += sz[v];
    }
  for (int i = n - 1; i >= 0; --i) {
    if (dp[u][i] && i + n - sz[u]) dp[u][i + n - sz[u]] = 1;
  }
  for (int i = n - 1; i >= 0; --i)
    if (dp[u][i]) ans[i] = 1;
}
void init() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}
void solve() {
  dfs(1, 0);
  vector<int> v;
  for (int i = 1; i < n - 1; ++i)
    if (ans[i]) v.push_back(i);
  cout << v.size() << '\n';
  for (auto i : v) cout << i << ' ' << n - 1 - i << '\n';
}
int main() {
  init();
  solve();
}
