#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
vector<int> g[N];
vector<pair<int, int> > ans;
int M = 0;
void dfs(int u, int par, int t) {
  ans.push_back({u, t});
  int rem = (int)g[u].size() - (par != -1);
  int cur_t = t;
  for (int v : g[u]) {
    if (v != par) {
      if (cur_t == M) {
        ans.push_back({u, (t - 1) - rem});
        cur_t = (t - 1) - rem;
      }
      dfs(v, u, cur_t + 1);
      ans.push_back({u, cur_t + 1});
      cur_t++;
      rem--;
    }
  }
  if (par != -1 && cur_t != t - 1) {
    assert(cur_t > t - 1);
    ans.push_back({u, t - 1});
    cur_t = t - 1;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    M = max(M, (int)g[i].size());
  }
  dfs(0, -1, 0);
  cout << (int)ans.size() << "\n";
  for (auto it : ans) {
    cout << it.first + 1 << " " << it.second << "\n";
  }
  return 0;
}
