#include <bits/stdc++.h>
using namespace std;
int n;
int d[300005], mxd;
vector<int> G[300005];
vector<pair<int, int> > Ans;
void DFS(int u, int p, int t) {
  int ot = t;
  Ans.push_back({u, t});
  for (int v : G[u])
    if (v != p) {
      if (t == mxd) t = mxd - d[u], Ans.push_back({u, t});
      ++t;
      DFS(v, u, t);
      Ans.push_back({u, t});
    }
  if (p && t != ot - 1) t = ot - 1, Ans.push_back({u, t});
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 2; i <= (n); ++i)
    scanf("%d%d", &x, &y), G[x].push_back(y), G[y].push_back(x), ++d[x], ++d[y];
  mxd = *max_element(d + 1, d + n + 1);
  DFS(1, 0, 0);
  printf("%d\n", (int)Ans.size());
  for (pair<int, int> p : Ans) printf("%d %d\n", p.first, p.second);
  return 0;
}
