#include <bits/stdc++.h>
using namespace std;
void read(long long &a) {
  a = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = (a << 1) + (a << 3) + c - '0';
    c = getchar();
  }
}
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
long long reset(long long n, long long pos) { return n = n & ~(1LL << pos); }
bool check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long msb(long long mask) { return (mask & (-mask)); }
long long cnt_on(long long mask) { return __builtin_popcountll(mask); }
long long mul(long long a, long long b) {
  long long c;
  c = (a % 1000000007 * b % 1000000007) % 1000000007;
  return c;
}
long long add(long long a, long long b) {
  long long c;
  c = (a % 1000000007 + b % 1000000007) % 1000000007;
  return c;
}
long long sub(long long a, long long b) {
  long long c;
  c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %
      1000000007;
  return c;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long exgcd(long long x, long long y, long long &a, long long &b) {
  int flag = 0;
  long long t, la = 1, lb = 0, ra = 0, rb = 1;
  while (x % y) {
    if (flag == 0)
      la -= x / y * ra, lb -= x / y * rb;
    else
      ra -= x / y * la, rb -= x / y * lb;
    t = x, x = y, y = t % y;
    flag = 1 - flag;
  }
  if (flag == 0)
    a = ra, b = rb;
  else
    a = la, b = lb;
  return y;
}
long long n;
vector<long long> graph[5004];
bitset<5002> cnt[5004];
bitset<5002> ac_cnt;
long long sz[5004];
void dfs(long long src, long long par) {
  cnt[src].reset();
  sz[src] = 1;
  for (long long i = 0; i < graph[src].size(); i++) {
    long long adj = graph[src][i];
    if (adj != par) {
      dfs(adj, src);
      sz[src] += sz[adj];
      cnt[src] = ((cnt[src] << sz[adj]) | (cnt[src]));
      cnt[src][sz[adj]] = 1;
    }
  }
  cnt[src] = (((cnt[src] << (n - sz[src]))) | (cnt[src]));
  cnt[src][n - sz[src]] = 1;
  ac_cnt |= cnt[src];
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    scanf("%lld %lld", &u, &v);
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs(1, -1);
  vector<pair<long long, long long> > ase;
  for (long long i = 1; i < n - 1; i++) {
    if (ac_cnt[i] == 1) ase.push_back(pair<long long, long long>(i, n - 1 - i));
  }
  cout << ase.size() << endl;
  for (long long i = 0; i < ase.size(); i++) {
    cout << ase[i].first << " " << ase[i].second << endl;
  }
  return 0;
}
