#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
int T;
vector<int> g[N];
vector<pair<int, int> > out;
void dfs(int v, int p, int t) {
  out.push_back({v, t});
  int tin = t;
  int restart = t - (int)(g[v]).size();
  bool re = false;
  for (int u : g[v]) {
    if (u == p) continue;
    if (t == T) {
      re = true;
      t = restart;
      out.push_back({v, t});
    }
    ++t;
    ++restart;
    dfs(u, v, t);
    out.push_back({v, t});
  }
  if (!re && p != -1) {
    t = tin - 1;
    out.push_back({v, t});
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n == 1) {
    printf("1\n");
    printf("1 0\n");
    return 0;
  }
  T = 0;
  for (int i = 1; i <= n; ++i) T = max(T, (int)(g[i]).size());
  dfs(1, -1, 0);
  printf("%d\n", (int)(out).size());
  for (auto& [v, t] : out) printf("%d %d\n", v, t);
  printf("\n");
}
