#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = (1e9);
int ans[((200000 + 4) * 2)][2];
int n, en, an, head[(200000 + 4)], du[(200000 + 4)], maxd;
struct edge {
  int v, nxt;
} e[((200000 + 4) * 2)];
void adde(int u, int v) {
  e[en].v = v;
  e[en].nxt = head[u];
  head[u] = en++;
}
void P(int x, int t) {
  ans[++an][0] = x;
  ans[an][1] = t;
}
void dfs(int x, int pre, int tim) {
  int t0 = tim;
  int sn = du[x] - (x != 1);
  P(x, tim);
  for (int i = head[x]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (v == pre) continue;
    if (tim == maxd) {
      tim -= (sn + 1);
      P(x, tim);
    }
    tim++;
    dfs(v, x, tim);
    P(x, tim);
  }
  if (x != 1 && tim != t0 - 1) P(x, t0 - 1);
}
int main() {
  scanf("%d", &n);
  memset(du, 0, sizeof(du));
  memset(head, -1, sizeof(head));
  en = 0;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adde(u, v);
    adde(v, u);
    du[u]++;
    du[v]++;
  }
  maxd = 0;
  for (int i = 1; i <= n; i++) maxd = max(maxd, du[i]);
  an = 0;
  dfs(1, -1, 0);
  printf("%d\n", an);
  for (int i = 1; i <= an; i++) {
    printf("%d %d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
