#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
int N, M;
vector<pair<int, int> > ops;
vector<int> edg[NMAX];
int solve(int nod, int t, int fth) {
  ops.push_back({nod, t});
  int trg = (t - 1);
  int rem = 0;
  for (auto nxt : edg[nod])
    if (nxt != fth) rem++;
  for (auto nxt : edg[nod]) {
    if (nxt == fth) continue;
    if (t == M) {
      t = trg - rem;
      ops.push_back({nod, t});
    }
    assert(solve(nxt, t + 1, nod) == t);
    rem--;
    t++;
    ops.push_back({nod, t});
  }
  if (t != trg && trg != -1) {
    assert(trg < t);
    t = trg;
    ops.push_back({nod, t});
  }
  return t;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edg[x].push_back(y);
    edg[y].push_back(x);
  }
  for (int i = 1; i <= N; i++) M = max(M, (int)edg[i].size());
  solve(1, 0, 0);
  printf("%d\n", (int)ops.size());
  for (auto x : ops) printf("%d %d\n", x.first, x.second);
  return 0;
}
