#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long INF = 8e18;
const int maxn = 5e5 + 5;
vector<int> e[maxn];
vector<pair<int, int> > ans;
int deg[maxn], lim;
inline void dfs(int u, int pre, int ti) {
  int go = ti - 1;
  ans.push_back({u, ti});
  for (auto v : e[u]) {
    if (v == pre) continue;
    if (ti == lim) {
      ti = lim - deg[u];
      ans.push_back({u, ti});
    }
    ++ti;
    dfs(v, u, ti);
    ans.push_back({u, ti});
  }
  if (u != 1 && ti != go) {
    ti = go;
    ans.push_back({u, ti});
  }
  ++ti;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
    ++deg[u], ++deg[v];
    lim = max({lim, deg[u], deg[v]});
  }
  dfs(1, 1, 0);
  cout << ans.size() << '\n';
  for (auto &x : ans) cout << x.first << ' ' << x.second << '\n';
  return 0;
}
