#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 6;
int n, D;
vector<int> e[N];
queue<pair<int, int> > ans;
void dfs(int u, int f, int c) {
  ans.push({u, c});
  int d = e[u].size();
  int p = c;
  for (auto v : e[u])
    if (v != f) {
      if (p == D) p = D - d, ans.push({u, p});
      dfs(v, u, ++p);
    }
  if (f && p != c - 1) ans.push({u, c - 1});
  if (f) ans.push({f, c});
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  if (n == 1) return puts("1\n1 0"), 0;
  for (int i = 1; i <= n; ++i) D = max(D, (int)e[i].size());
  dfs(1, 0, 0);
  cerr << "------------------------\n";
  printf("%lld\n", ans.size());
  while (!ans.empty()) {
    auto t = ans.front();
    ans.pop();
    printf("%d %d\n", t.first, t.second);
  }
}
