#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
const int N = 1e5 + 4;
int n, D;
vector<int> e[N];
vector<pair<int, int> > ans;
void dfs(int x, int fa, int t) {
  ans.push_back(make_pair(x, t));
  int tiao = D - (signed)e[x].size(), ed = t - 1;
  for (auto v : e[x])
    if (v != fa) {
      if (t == D) ans.push_back(make_pair(x, t = tiao));
      dfs(v, x, ++t);
      ans.push_back(make_pair(x, t));
    }
  if (x > 1 && t != ed) {
    assert(t > ed);
    ans.push_back(make_pair(x, ed));
  }
}
int main() {
  n = read();
  for (int i = 1, u, v; i < n; i++) {
    u = read();
    v = read();
    e[u].push_back(v);
    e[v].push_back(u);
  }
  D = e[1].size();
  for (int i = 1; i <= n; i++) D = max(D, (signed)e[i].size());
  dfs(1, 0, 0);
  cout << ans.size() << "\n";
  for (auto v : ans) cout << v.first << " " << v.second << "\n";
  return (0 - 0);
}
