#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
  return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int n;
vector<int> adj[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
vector<pair<int, int> > ans;
void dfs(int u, int pr, int t) {
  ans.push_back({u, t});
  vector<int> children;
  for (int v : adj[u]) {
    if (v != pr) {
      children.push_back(v);
    }
  }
  int children_left = ((int)children.size());
  int initial_t = t;
  bool flag = false;
  for (int x : children) {
    if (u != 1 && !flag && children_left < initial_t) {
      t = initial_t - children_left - 1;
      ans.push_back({u, t});
      flag = true;
    }
    dfs(x, u, t + 1);
    t++;
    ans.push_back({u, t});
    children_left--;
  }
  if (u != 1 && !flag) {
    t = initial_t - 1;
    ans.push_back({u, t});
    flag = true;
  }
}
void solve() {
  dfs(1, 1, 0);
  cout << ((int)ans.size()) << '\n';
  for (auto it : ans) {
    cout << it.first << " " << it.second << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
