#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 200010;
const int INF = 1e9;
const int Mod = 998244353LL;
int mx;
int N;
int tms = 0;
pair<int, int> sta[MAXN * 10 + 1];
int top;
int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt;
int deg[MAXN + 1];
inline void insert(int u, int v) {
  Node[++cnt] = v;
  Next[cnt] = Root[u];
  Root[u] = cnt;
  return;
}
inline void solve(int k, int Fa, int val) {
  if (k != 1) --deg[k];
  int last = deg[k];
  sta[++top] = make_pair(k, tms);
  bool flag = 0;
  if (tms == mx && val != -1) {
    tms = max(val - last, 0);
    if (tms + last != val) flag = 1;
    sta[++top] = make_pair(k, tms);
  }
  for (int x = Root[k]; x; x = Next[x]) {
    int v = Node[x];
    if (v == Fa) continue;
    ++tms;
    --last;
    solve(v, k, ((tms == val && flag) ? tms : tms - 1));
    ++tms;
    sta[++top] = make_pair(k, tms);
    if (tms == mx && val != -1) {
      tms = max(val - last, 0);
      if (tms + last != val) flag = 1;
      sta[++top] = make_pair(k, tms);
    }
  }
  if (val != -1 && tms > val) {
    sta[++top] = make_pair(k, val);
    tms = val;
  }
  return;
}
int main() {
  N = read();
  for (int i = 1; i < N; i++) {
    int u = read(), v = read();
    insert(u, v);
    insert(v, u);
    ++deg[u];
    ++deg[v];
  }
  mx = 0;
  for (int i = 1; i <= N; i++) mx = max(mx, deg[i]);
  solve(1, 0, -1);
  printf("%d\n", top);
  for (int i = 1; i <= top; i++) printf("%d %d\n", sta[i].first, sta[i].second);
  return 0;
}
