#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
vector<int> g[N];
vector<pair<int, int> > ans;
void dfs(int u, int p, int k) {
  vector<int> child;
  for (int v : g[u]) {
    if (v != p) {
      child.push_back(v);
    }
  }
  bool niche = 0;
  int now = k;
  for (int i = 0; i < child.size(); i++) {
    int v = child[i];
    if (niche == 0) {
      int x = k - 1 - (child.size() - i);
      if (x >= 0) {
        ans.push_back({u, x});
        now = x;
        niche = 1;
      }
    }
    now++;
    ans.push_back({v, now});
    dfs(v, u, now);
    ans.push_back({u, now});
  }
  if (niche == 0) {
    ans.push_back({u, k - 1});
    now = k - 1;
  }
  assert(now == k - 1);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans.push_back({1, 0});
  int u = 1;
  int now = 0;
  for (int v : g[u]) {
    now++;
    ans.push_back({v, now});
    dfs(v, u, now);
    ans.push_back({u, now});
  }
  cout << ans.size() << "\n";
  for (pair<int, int> x : ans) cout << x.first << " " << x.second << "\n";
}
