#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int N = 100005;
vector<int> graf[N];
vector<pair<int, int> > v;
int n, a, b, i, maxx;
void go(int w, int o, int act) {
  v.push_back(pair<int, int>(w, act));
  int left = graf[w].size();
  if (o != -1) left--;
  int start = act;
  if (act == maxx) {
    act = act - 1 - left;
    v.push_back(pair<int, int>(w, act));
  }
  for (auto& w2 : graf[w])
    if (w2 != o) {
      act++;
      go(w2, w, act);
      v.push_back(pair<int, int>(w, act));
      left--;
      if (act == maxx && o != -1) {
        act = start - 1 - left;
        v.push_back(pair<int, int>(w, act));
      }
    }
  if (act != start - 1 && o != -1) v.push_back(pair<int, int>(w, start - 1));
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    printf("1\n1 0\n");
    return 0;
  }
  if (n == 2) {
    printf("4\n1 0\n2 1\n2 0\n1 1\n");
    return 0;
  }
  for (i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  for (i = 1; i <= n; i++) maxx = max(maxx, (int)graf[i].size());
  go(1, -1, 0);
  printf("%d\n", v.size());
  for (auto& w : v) printf("%d %d\n", w.first, w.second);
  return 0;
}
