#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 1 << 17;
vector<int> G[maxN];
vector<pair<int, int> > ans;
int D, ctr;
void dfs(int v, int fat, int des) {
  ans.push_back({v, ctr});
  for (int i = (0); i < (((int)(G[v]).size())); i++)
    if (G[v][i] == fat) {
      swap(G[v].back(), G[v][i]);
      G[v].pop_back();
      break;
    }
  for (int i = (0); i < (((int)(G[v]).size())); i++) {
    int u = G[v][i];
    if (ctr == D) {
      ctr = des - (((int)(G[v]).size()) - i);
      ans.push_back({v, ctr});
    }
    dfs(u, v, ctr++);
    ans.push_back({v, ctr});
  }
  if (ctr > des) ans.push_back({v, ctr = des});
  ctr++;
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = (1); i < (n + 1); i++) D = max(D, ((int)(G[i]).size()));
  dfs(1, 0, D);
  printf("%d\n", ((int)(ans).size()));
  for (auto p : ans) printf("%d %d\n", p.first, p.second);
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
