#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
const int M = 1e6 + 10;
const int N = 1e5 + 10;
inline long long read() {
  long long b = 1, sum = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') b = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return b * sum;
}
int a[N], in[N], d[N];
int n, m, k, T;
int vis[N];
vector<int> e[N];
vector<pair<int, int> > ans;
void dfs(int x, int _fa, int need) {
  int i, j;
  if (x == 1) {
    for (i = 0; i < e[x].size(); i++) {
      int y = e[x][i];
      ans.push_back({y, i + 1});
      dfs(y, x, i);
    }
    return;
  }
  int cha = need - in[x] + 1, sum = 0;
  if (in[x] == 1) {
    ans.push_back({x, need});
  } else if (cha >= 0) {
    ans.push_back({x, cha});
    for (i = 0; i < e[x].size(); i++) {
      int y = e[x][i];
      if (y == _fa) continue;
      ans.push_back({y, cha + sum + 1});
      dfs(y, x, cha + sum);
      sum++;
    }
  } else {
    int now = need + 1, sum = 0;
    for (i = 0; sum < -cha && i < e[x].size(); i++) {
      int y = e[x][i];
      if (y == _fa) continue;
      ans.push_back({y, now + 1});
      dfs(y, x, now);
      now++;
      sum++;
    }
    ans.push_back({x, 0});
    sum = 0;
    for (; i < e[x].size(); i++) {
      int y = e[x][i];
      if (y == _fa) continue;
      ans.push_back({y, sum + 1});
      dfs(y, x, sum);
      sum++;
    }
  }
  ans.push_back({_fa, need + 1});
}
int main() {
  int i, j;
  n = read();
  for (i = 1; i <= n - 1; i++) {
    int x = read(), y = read();
    e[x].push_back(y);
    e[y].push_back(x);
    in[x]++;
    in[y]++;
  }
  ans.push_back({1, 0});
  dfs(1, 0, 0);
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
