#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
vector<int> parent;
list<pair<int, int>> ans;
int len = 0;
int dfs(int u, int id) {
  ans.push_back({u + 1, id});
  int now = id, cnt = 0;
  for (int v : G[u]) {
    if (parent[u] != v) {
      parent[v] = u;
      if (now + 1 <= len) {
        now = dfs(v, now + 1);
        ans.push_back({u + 1, now});
      } else {
        int child = G[u].size() - (parent[u] != -1) - cnt;
        now = id - 1 - child;
        ans.push_back({u + 1, now});
        now = dfs(v, now + 1);
        ans.push_back({u + 1, now});
      }
      ++cnt;
    }
  }
  if (parent[u] != -1 && now != id - 1) ans.push_back({u + 1, id - 1});
  return id;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  G.resize(n);
  parent.resize(n, -1);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i < n; ++i) len = max(len, int(G[i].size()));
  dfs(0, 0);
  cout << ans.size() << '\n';
  for (auto it = ans.begin(); it != ans.end(); ++it) {
    cout << it->first << " " << it->second << '\n';
  }
  return 0;
}
