#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u / 2;
const long long linf = ~0ull / 2;
const int maxn = 5e3 + 20;
vector<int> adj[maxn];
bool pos[maxn], dp[maxn];
int s[maxn], n;
void dfs(int root, int par = -1) {
  s[root] = 1;
  for (int x : adj[root])
    if (x != par) {
      dfs(x, root);
      s[root] += s[x];
    }
  for (int x : adj[root])
    if (x != par)
      for (int i = n; i >= 0; i--)
        if (i - s[x] >= 0) dp[i] |= dp[i - s[x]];
  for (int i = n; i >= 0; i--)
    if (i - (n - s[root]) >= 0) dp[i] |= dp[i - (n - s[root])];
  for (int i = 1; i < n; i++) pos[i] |= dp[i], dp[i] = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dp[0] = 1;
  dfs(0);
  int c = 0;
  for (int i = 0; i < n - 1; i++)
    if (pos[i]) c++;
  cout << c << endl;
  for (int i = 0; i < n - 1; i++)
    if (pos[i]) cout << i << " " << n - i - 1 << endl;
  return 0;
}
