#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 10;
int n, tot, du[maxn], head[maxn], maxx, num;
pair<int, int> ans[maxn];
struct Le {
  int nt, to;
} edge[maxn];
void add(int f, int t) {
  edge[++num].nt = head[f];
  edge[num].to = t;
  head[f] = num;
}
void dfs(int u, int fa, int now) {
  int from = now;
  ans[++tot] = make_pair(u, now);
  for (int i = head[u]; i; i = edge[i].nt) {
    if (now == maxx) {
      now = maxx - du[u];
      ans[++tot] = make_pair(u, now);
    }
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u, now + 1);
    now++;
    ans[++tot] = make_pair(u, now);
  }
  if (u != 1 && now != from - 1) ans[++tot] = make_pair(u, from - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
    du[v]++;
    du[u]++;
    maxx = max(maxx, max(du[u], du[v]));
  }
  dfs(1, 0, 0);
  cout << tot << "\n";
  for (int i = 1; i <= tot; ++i)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return 0;
}
