#include <bits/stdc++.h>
using namespace std;
long long binpow(long long base, long long exp) {
  long long mod = 1000000007LL;
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % mod;
    exp = exp >> 1;
    base = (base * base) % mod;
  }
  return res;
}
long long mod(long long x) {
  return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);
}
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const long long N = 5005;
void sieve(long long N) {
  bool prime[N + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= N; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= N; i += p) prime[i] = false;
    }
  }
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 1; i <= n; i++) {
    res = res * 1ll * i % 1000000007LL;
  }
  return res;
}
long long C(long long n, long long k) {
  return fact(n) * 1ll * binpow(fact(k), 1000000007LL - 2) % 1000000007LL *
         1ll * binpow(fact(n - k), 1000000007LL - 2) % 1000000007LL;
}
long long n;
unordered_map<long long, vector<long long> > adj;
vector<bool> pos(N, 0);
vector<long long> subtree(N);
long long dfs(long long src, long long par) {
  subtree[src] = 1;
  vector<long long> degree;
  for (auto x : adj[src]) {
    if (x != par) {
      subtree[src] += dfs(x, src);
      degree.push_back(subtree[x]);
    }
  }
  degree.push_back(n - subtree[src]);
  vector<bool> local(n + 1, false);
  local[0] = true;
  for (auto x : degree) {
    for (long long i = n; i >= x; i--) {
      if (local[i - x]) {
        local[i] = true;
      }
    }
  }
  for (long long i = 0; i <= n; i++) {
    if (local[i]) {
      pos[i] = true;
    }
  }
  return subtree[src];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, -1);
  vector<long long> ans;
  for (long long i = 1; i <= n - 2; i++) {
    if (pos[i]) {
      ans.push_back(i);
    }
  }
  cout << ans.size() << "\n";
  for (auto x : ans) {
    cout << x << " " << n - 1 - x << " "
         << "\n";
  }
  return 0;
}
