#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, sz[N];
bool dp[N][N], ans[N][N];
vector<int> adj[N];
void dfs(int v, int p = -1) {
  sz[v] = 1;
  for (auto u : adj[v])
    if (u ^ p) dfs(u, v), sz[v] += sz[u];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  for (int v = 0; v < n; v++) {
    vector<int> vec;
    dfs(v);
    for (auto u : adj[v]) vec.push_back(sz[u]);
    for (int i = 0; i <= vec.size(); i++)
      for (int j = 0; j < n - 1; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < vec.size(); i++)
      for (int j = 0; j < n - 1; j++) {
        dp[i + 1][j] |= dp[i][j];
        if (j >= vec[i]) dp[i + 1][j] |= dp[i][j - vec[i]];
      }
    for (int j = 1; j < n - 1; j++) ans[j][n - 1 - j] |= dp[(int)vec.size()][j];
  }
  vector<pair<int, int> > res;
  for (int i = 1; i < n - 1; i++)
    if (ans[i][n - i - 1]) res.push_back({i, n - i - 1});
  cout << res.size() << "\n";
  for (auto p : res) cout << p.first << " " << p.second << "\n";
}
