#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-11;
char TEMPORARY_CHAR;
const int INF = 0x3f3f3f3f;
const int N = 1 << 16;
inline void input(int& a) {
  a = 0;
  while ((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') {
  }
  while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {
    a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
    TEMPORARY_CHAR = getchar();
  }
}
vector<int> g[5001];
bool used[5001];
bool ans[5001];
int n;
int go(int v) {
  used[v] = true;
  int s = 0;
  vector<int> p;
  vector<bool> can[2];
  for (__typeof((g[v]).begin()) it = (g[v]).begin(); it != (g[v]).end(); it++) {
    int to = *it;
    if (!used[to]) {
      p.push_back(go(to));
      s += p.back();
    }
  }
  p.push_back(n - s - 1);
  can[0].resize(n);
  can[0][0] = true;
  int cur = 0;
  for (__typeof((p).begin()) it = (p).begin(); it != (p).end(); it++) {
    can[cur ^ 1] = can[cur];
    int c = *it;
    for (int i = 0; i < (int)(n - c); i++)
      if (can[cur][i]) {
        can[cur ^ 1][i + c] = true;
        ans[i + c] = true;
      }
    cur ^= 1;
  }
  return s + 1;
}
int main() {
  input(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    int(a);
    input((a));
    ;
    int(b);
    input((b));
    ;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  memset((used), 0, sizeof(used));
  memset((ans), 0, sizeof(ans));
  go(0);
  int k = 0;
  for (int i = 1; i < n - 1; i++) {
    k += ans[i];
  }
  cout << k << endl;
  for (int i = 1; i < n - 1; i++) {
    if (ans[i]) cout << i << " " << n - 1 - i << endl;
  }
  return 0;
}
