#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9;
const long long OO = 1e18;
const double eps = 1e-9;
void solve(long long test_case);
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  if (0) cin >> T;
  for (long long t = 1; t <= T; t++) solve(t);
  return 0;
}
long long n;
vector<vector<long long> > g;
vector<pair<long long, long long> > ans;
long long T = 0, t = 0;
void dfs(long long u, long long p = -1, long long pt = -1) {
  ans.push_back({u, t});
  long long f = 0;
  for (long long v : g[u])
    if (v != p) f++;
  for (long long v : g[u])
    if (v != p) {
      if (t == T) {
        t = pt - 1 - f;
        ans.push_back({u, t});
      }
      t++;
      dfs(v, u, t);
      ans.push_back({u, t});
      --f;
    }
  if (p == -1) return;
  if (t >= pt) t = pt - 1, ans.push_back({u, t});
  ++t;
}
void solve(long long test_case) {
  cin >> n;
  g.resize(n);
  for (long long i = 0; i < (n - 1); i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (long long i = 0; i < (n); i++) T = max(T, ((long long)(g[i].size())));
  dfs(0);
  cout << (long long)(ans.size()) << '\n';
  for (auto p : ans) cout << p.first + 1 << " " << p.second << '\n';
}
