#include <bits/stdc++.h>
using namespace std;
int n, m, ans[1000005][2], deg[1000005], top, mxdeg;
int ver[1000005], nx[1000005], fi[1000005], cnt;
void add(int x, int y) {
  ver[++cnt] = y;
  nx[cnt] = fi[x];
  fi[x] = cnt;
}
void dfs(int x, int fa, int tim) {
  int nowt = tim;
  ans[++top][0] = x, ans[top][1] = nowt;
  if (tim == mxdeg) {
    nowt -= deg[x];
    ans[++top][0] = x, ans[top][1] = nowt;
  }
  for (int i = fi[x]; i; i = nx[i]) {
    int y = ver[i];
    if (y == fa) continue;
    nowt++;
    dfs(y, x, nowt);
    ans[++top][0] = x, ans[top][1] = nowt;
    if (nowt == mxdeg && nx[i] != 0) {
      nowt -= deg[x];
      ans[++top][0] = x, ans[top][1] = nowt;
    }
  }
  if (x != 1 && nowt != tim - 1) ans[++top][0] = x, ans[top][1] = tim - 1;
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    puts("1");
    puts("1 0");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
    deg[a]++;
    deg[b]++;
    mxdeg = max(mxdeg, max(deg[a], deg[b]));
  }
  dfs(1, 0, 0);
  printf("%d\n", top);
  for (int i = 1; i <= top; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
