#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000 + 5;
vector<vector<int>> g(MAX_N);
vector<int> sz(MAX_N);
vector<int> ok(MAX_N);
int calc(int node, int p) {
  sz[node] = 1;
  for (auto& to : g[node]) {
    if (to != p) {
      sz[node] += calc(to, node);
    }
  }
  return sz[node];
}
vector<pair<int, int>> ans;
int n;
void solve(int node, int p) {
  vector<int> poss;
  vector<int> dp(MAX_N);
  dp[0] = 1;
  if (node) poss.emplace_back(n - sz[node]);
  for (auto to : g[node]) {
    if (to != p) {
      poss.emplace_back(sz[to]);
    }
  }
  for (auto& coin : poss) {
    vector<int> nxt = dp;
    for (int i = coin; i < MAX_N; i++) {
      nxt[i] |= dp[i - coin];
    }
    dp = nxt;
  }
  for (int i = 1; i < MAX_N; i++) {
    if (dp[i]) {
      ok[i] = 1;
    }
  }
  for (auto to : g[node]) {
    if (to != p) {
      solve(to, node);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int st, et;
    cin >> st >> et;
    --st;
    --et;
    g[st].emplace_back(et);
    g[et].emplace_back(st);
  }
  calc(0, -1);
  solve(0, -1);
  vector<pair<int, int>> ans;
  for (int i = 1; i < n; i++) {
    if (ok[i] && n - i - 1) {
      ans.emplace_back(i, n - i - 1);
    }
  }
  cout << ans.size() << '\n';
  for (auto to : ans) cout << to.first << ' ' << to.second << '\n';
  return 0;
}
