#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const long long inf = 1e18 + 10;
int n;
vector<int> G[maxn];
vector<pair<int, int> > ans;
int du[maxn];
int T;
void dfs(int u, int fa, int pre) {
  int i = pre;
  int j = (int)G[u].size() - 1;
  ans.push_back({u, pre});
  for (auto v : G[u]) {
    if (v == fa) continue;
    if (++i <= T) {
      dfs(v, u, i);
    } else {
      i = pre - j - 1;
      ans.push_back({u, i});
      i++;
      dfs(v, u, i);
    }
    ans.push_back({u, i});
    j--;
  }
  if (u != 1) {
    if (i + 1 != pre) {
      ans.push_back({u, pre - 1});
    }
  }
}
int main(void) {
  scanf("%d", &(n));
  for (int i = (1); i < (n); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    du[u]++;
    du[v]++;
    T = max(du[u], T);
    T = max(du[v], T);
    G[v].push_back(u);
    G[u].push_back(v);
  }
  dfs(1, 0, 0);
  printf("%d\n", (int)ans.size());
  for (auto e : ans) printf("%d %d\n", e.first, e.second);
  return 0;
}
