#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool umax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
template <int sz>
using tut = array<int, sz>;
void usaco(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 2e5 + 5;
const int mod = (119 << 23) + 1;
const long long inf = 1e18;
const long double Pi = acos(-1);
void add(int& a, int b, int mod = ::mod) { a = (a + b) % mod; }
void sub(int& a, int b, int mod = ::mod) { a = ((a - b) % mod + mod) % mod; }
void mul(int& a, int b, int mod = ::mod) { a = (a * 1ll * b) % mod; }
int n, m, k, t, q, ans, res, a[N];
int mad;
vector<int> edges[N];
vector<pair<int, int> > rr;
void dfs(int u, int& t, int backT = -1, int p = -1) {
  rr.push_back({u, t});
  int cnt = (int)edges[u].size() - (p != -1);
  for (auto x : edges[u]) {
    if (x == p) continue;
    if (t == mad) {
      t = backT - cnt - 1;
      rr.push_back({u, t});
    }
    t++;
    dfs(x, t, t, u);
    rr.push_back({u, t});
    cnt--;
  }
  if (p == -1) return;
  if (t >= backT) {
    t = backT - 1;
    rr.push_back({u, t});
  }
  t++;
}
void solve(int t_case) {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b), edges[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) umax(mad, (int)edges[i].size());
  dfs(1, t);
  cout << (int)rr.size() << "\n";
  for (auto x : rr) cout << x.first << " " << x.second << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (0) {
    int t;
    cin >> t;
    for (int t_case = 1; t_case <= t; t_case++) solve(t_case);
  } else
    solve(1);
  return 0;
}
