#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
const int maxn = 1e6 + 10, lg = 20, mod = 1e9 + 7, inf = 1e18;
int n, dd;
vector<int> g[maxn];
vector<pair<int, int> > ans;
void dfs(int v = 1, int p = 0, int t = 0) {
  ans.push_back({v, t});
  int nt = t;
  for (auto u : g[v])
    if (u != p) {
      if (nt == dd)
        nt = t - 1 - ((int)(g[v].size()) - 1 - (dd - t)),
        ans.push_back({v, nt});
      dfs(u, v, ++nt);
      ans.push_back({v, nt});
    }
  if (t && nt > t - 1) ans.push_back({v, t - 1});
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u), g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) dd = max(dd, (int)(g[i].size()));
  dfs();
  cout << (int)(ans.size()) << endl;
  for (auto x : ans) cout << x.first << ' ' << x.second << endl;
  return 0;
}
