#include <bits/stdc++.h>
using namespace std;
const long long mxN = 5005;
vector<long long> g[mxN];
long long sz[mxN], n;
bitset<mxN> ans, temp[mxN];
void dfs(long long u, long long p) {
  sz[u] = 1;
  temp[u][0] = 1;
  for (auto v : g[u]) {
    if (v != p) {
      dfs(v, u);
      sz[u] += sz[v];
      temp[u] |= temp[u] << sz[v];
    }
  }
  temp[u] |= temp[u] << (n - sz[u]);
  ans |= temp[u];
}
void solve() {
  cin >> n;
  long long x, y;
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  set<long long> res;
  for (long long i = 1; i < n - 1; i++) {
    if (ans[i]) {
      res.insert(i);
    }
  }
  cout << res.size() << "\n";
  for (auto x : res) {
    cout << x << " " << (n - x - 1) << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
