#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int inf = 1e9;
int mod = 1e9 + 7;
vector<int> graph[N];
vector<pair<int, int>> path;
int T = 0;
void dfs(int cur, int prev, int t) {
  path.emplace_back(cur, t);
  int temp = t;
  int k = (int)graph[cur].size();
  if (prev != -1) k--;
  for (int u : graph[cur]) {
    if (u == prev) continue;
    if (t + 1 > T) {
      t = temp - 1 - k;
      path.emplace_back(cur, t);
    }
    k--;
    dfs(u, cur, t + 1);
    path.emplace_back(cur, t + 1);
    t++;
  }
  if (prev != -1 && temp - 1 < t) path.emplace_back(cur, temp - 1);
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) T = max(T, (int)graph[i].size());
  dfs(1, -1, 0);
  cout << (int)path.size() << "\n";
  for (auto it : path) cout << it.first << " " << it.second << "\n";
  return 0;
}
