#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream &operator<<(ostream &os, vector<A> v) {
  os << "{ ";
  for (auto &x : v) cout << x << " ";
  return os << "}";
}
template <class A>
ostream &operator<<(ostream &os, vector<vector<A>> v) {
  os << "{ " << v.front() << '\n';
  for (auto it = next(v.begin()); it != v.end(); it++)
    os << "  " << *it << '\n';
  return os << "}";
}
using VI = vector<int>;
using VVI = vector<VI>;
using II = pair<int, int>;
using VII = vector<II>;
using L = long long;
using VL = vector<L>;
using VB = vector<bool>;
using VVB = vector<VB>;
VVI graph;
VII ans;
int T;
void dfs(int v = 0, int f = -1, int t = 0) {
  ;
  ans.emplace_back(v, t);
  int faza = t + 1;
  int time = int(graph[v].size());
  bool cor = 0;
  if (t >= time) {
    cor = true;
    ans.emplace_back(v, t - time);
    faza = t - time + 1;
  }
  for (auto &u : graph[v]) {
    if (u != f) {
      dfs(u, v, faza);
      ans.emplace_back(v, faza);
      faza++;
      if (faza > time and !cor) {
        ans.emplace_back(v, 0);
        faza = 1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  graph.resize(n);
  for (decltype((n - 1) - 1) i = (0), i__ = ((n - 1) - 1); i <= i__; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  T = 1;
  for (decltype((n)-1) i = (0), i__ = ((n)-1); i <= i__; i++)
    T = max(T, int(graph[i].size()));
  dfs();
  ans.pop_back();
  cout << int(ans.size()) << "\n";
  for (auto &p : ans) cout << p.first + 1 << " " << p.second << "\n";
  return 0;
}
