#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> parent;
vector<vector<int>> children;
int max_degree;
vector<pair<int, int>> result;
void into(int root, int time) {
  int orig_time = time;
  result.emplace_back(root + 1, time);
  for (int i = 0; i < children[root].size(); i++) {
    time++;
    if (time > max_degree) {
      time = orig_time - ((int)children[root].size()) + i;
      result.emplace_back(root + 1, time - 1);
    }
    into(children[root][i], time);
    result.emplace_back(root + 1, time);
  }
  if (root != 0 && time > orig_time - 1) {
    result.emplace_back(root + 1, orig_time - 1);
  }
}
int main() {
  int n;
  cin >> n;
  parent = vector<int>(n, -1);
  children = vector<vector<int>>(n, vector<int>());
  vector<vector<int>> adj(n, vector<int>());
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  parent[0] = 0;
  stack<int> s;
  s.push(0);
  while (!s.empty()) {
    int cur = s.top();
    s.pop();
    for (int nb : adj[cur]) {
      if (parent[nb] == -1) {
        s.push(nb);
        children[cur].push_back(nb);
      } else {
        parent[cur] = nb;
      }
    }
  }
  parent[0] = -1;
  max_degree = 0;
  for (int i = 0; i < n; i++) {
    max_degree = max(max_degree, ((int)adj[i].size()));
  }
  result = vector<pair<int, int>>();
  into(0, 0);
  cout << result.size() << endl;
  for (auto [a, b] : result) {
    cout << a << " " << b << endl;
  }
  return 0;
}
