#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
void rec_solve(const int what, const int enter, const int parent,
               const vector<vector<int>> &tree, vector<pair<int, int>> &sol) {
  int n = tree.size(),
      need = (parent == -1 ? tree[what].size() : tree[what].size() - 1);
  vector<int> values(need + 2);
  for (int i = 0; i < need + 2; i += 1) values[need + 1 - i] = enter - 1 - i;
  values[0] = enter;
  for (int i = enter + 1; i < need + 2; i += 1) values[i - enter] = i;
  int vs = values.size();
  int ci = 0, vi = 0;
  for (int i = 0; i < need; i += 1) {
    if (tree[what][ci] == parent) ci++;
    if (vi != need + 1 && values[vi] > values[vi + 1]) {
      sol.emplace_back(what, values[vi]);
      vi++;
    }
    sol.emplace_back(what, values[vi]);
    rec_solve(tree[what][ci], values[vi] + 1, what, tree, sol);
    ci++, vi++;
  }
  if (vi != need + 1 && values[vi] > values[vi + 1]) {
    sol.emplace_back(what, values[vi]);
    vi++;
  }
  sol.emplace_back(what, values[vi]);
}
int main() {
  int n;
  scanf("%d\n", &n);
  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; i += 1) {
    int a, b;
    scanf("%d %d\n", &a, &b);
    a--, b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<pair<int, int>> sol;
  rec_solve(0, 0, -1, tree, sol);
  cout << sol.size() << endl;
  for (const auto &p : sol) printf("%d %d\n", p.first + 1, p.second);
  return 0;
}
