#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> adj[N];
bool vis[N];
vector<pair<int, int> > ans;
int t = 0, deg = 0;
void dfs(int v) {
  if (vis[v]) return;
  vis[v] = true;
  ans.push_back(make_pair(v, t));
  int back = t;
  int count = 0;
  for (auto &u : adj[v]) {
    if (!vis[u]) count++;
  }
  for (auto &u : adj[v]) {
    if (!vis[u]) {
      if (t >= deg) {
        t -= count + 1;
        ans.push_back(make_pair(v, t));
      }
      t++;
      dfs(u);
      t++;
      ans.push_back(make_pair(v, t));
    }
  }
  if (t >= back) {
    ans.push_back(make_pair(v, back - 1));
    t = back - 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < n; i++) deg = max(deg, (int)adj[i].size());
  dfs(0);
  cout << (int)ans.size() - 1 << endl;
  for (int i = 0; i < (int)ans.size() - 1; i++) {
    cout << ans[i].first + 1 << " " << ans[i].second << endl;
  }
}
