#include <bits/stdc++.h>
using namespace std;
class Roads {
 public:
  Roads() = default;
  explicit Roads(size_t capacity) : data(capacity) {}
  void Add(size_t src, size_t dst) {
    data[src].insert(dst);
    data[dst].insert(src);
  }
  vector<pair<size_t, size_t>>& Walk(size_t start, size_t& time) {
    size_t init = time;
    route.emplace_back(start, time++);
    size_t c = data[start].size();
    size_t i = 0;
    for (size_t n : data[start]) {
      if (time > init && init + i > c) {
        time = init + i - c - 1;
        route.emplace_back(start, time++);
      }
      data[n].erase(start);
      Walk(n, time);
      route.emplace_back(start, time++);
      i++;
    }
    if (time > init && init > 0) {
      time = init - 1;
      route.emplace_back(start, time++);
    }
    return route;
  }

 private:
  vector<set<size_t>> data;
  vector<pair<size_t, size_t>> route;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  size_t n;
  cin >> n;
  Roads r(n + 1);
  size_t src, dst;
  while (n-- > 1) {
    cin >> src >> dst;
    r.Add(src, dst);
  }
  size_t t = 0;
  auto route = r.Walk(1, t);
  cout << route.size() << '\n';
  for (auto p : route) {
    cout << p.first << ' ' << p.second << '\n';
  }
  return 0;
}
