#include <bits/stdc++.h>
using namespace std;
template <class Cont>
int sz(const Cont& cont) {
  return cont.size();
}
int mx;
vector<pair<int, int>> res;
vector<bool> vis;
void Fill(int vert, int time, const vector<vector<int>>& adj) {
  res.emplace_back(vert, time);
  vis[vert] = true;
  int start = time;
  int ch = sz(adj[vert]) - 1;
  if (ch < start - 1) {
    time -= ch + 1;
    res.emplace_back(vert, time);
  }
  for (int nxt : adj[vert]) {
    if (!vis[nxt]) {
      if (ch == start - 1) {
        time = 0;
        res.emplace_back(vert, time);
      }
      ++time;
      Fill(nxt, time, adj);
      res.emplace_back(vert, time);
      --ch;
    }
  }
  if (start == 1) res.emplace_back(vert, 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vis.assign(n, false);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  if (n == 1) {
    cout << "1\n1 0\n";
    return 0;
  }
  int deg = 0;
  for (auto& a : adj) deg = max<int>(deg, a.size());
  mx = deg;
  Fill(0, 0, adj);
  cout << res.size() << '\n';
  for (auto [v, t] : res) cout << v + 1 << ' ' << t << '\n';
  return 0;
}
