#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NN = 101010;
vector<int> adj[NN];
vector<pii> ans;
int mx;
void dfs(int u, int t = 0, int fa = -1) {
  ans.push_back(pii(u, t));
  int tt = t;
  vector<int> res;
  for (int v : adj[u]) {
    if (v == fa) continue;
    if (tt < mx) {
      tt++;
      dfs(v, tt, u);
      ans.push_back(pii(u, tt));
    } else {
      res.push_back(v);
    }
  }
  if (res.size()) {
    tt = t - res.size() - 1;
    ans.push_back(pii(u, tt));
    for (int v : res) {
      tt++;
      dfs(v, tt, u);
      ans.push_back(pii(u, tt));
    }
  } else {
    if (t > 0) ans.push_back(pii(u, t - 1));
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) mx = max(mx, (int)adj[i].size());
  dfs(1);
  cout << ans.size() << endl;
  for (auto p : ans) {
    printf("%d %d\n", p.first, p.second);
  }
  return 0;
}
