#include <bits/stdc++.h>
using namespace std;
const int SZ = 1e5 + 5;
vector<int> adj_[SZ], children[SZ];
vector<pair<int, int>> res;
void dfs(int v, int par) {
  for (int nv : adj_[v]) {
    if (nv == par) continue;
    children[v].push_back(nv);
    dfs(nv, v);
  }
}
void solve(int v, int t) {
  res.push_back({v, t});
  if (adj_[v].size() > t) {
    int cur = t + 1;
    for (int c : children[v]) {
      solve(c, cur);
      res.push_back({v, cur});
      if (++cur > adj_[v].size()) {
        res.push_back({v, 0});
        cur = 1;
      }
    }
  } else {
    int cur = t - adj_[v].size();
    res.push_back({v, cur++});
    for (int c : children[v]) {
      solve(c, cur);
      res.push_back({v, cur++});
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    adj_[a].push_back(b);
    adj_[b].push_back(a);
  }
  dfs(1, -1);
  solve(1, 0);
  res.pop_back();
  cout << res.size() << '\n';
  for (const auto& p : res) cout << p.first << ' ' << p.second << '\n';
}
