#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int T;
vector<pair<int, int> > ans;
void dfs(int u, int par, vector<int> g[], int t) {
  if (par != -1) g[u].erase(find((g[u]).begin(), (g[u]).end(), par));
  int k = g[u].size();
  ans.push_back({u, t});
  if (t + k <= T) {
    for (int i = 0; i < k; i++) {
      dfs(g[u][i], u, g, t + i + 1);
      ans.push_back({u, t + i + 1});
    }
    if (par != -1) ans.push_back({u, t - 1});
  } else {
    for (int i = 0; t + i < T; i++) {
      dfs(g[u][i], u, g, t + i + 1);
      ans.push_back({u, t + i + 1});
    }
    ans.push_back({u, T - k - 1});
    for (int i = T - t; i < k; i++) {
      dfs(g[u][i], u, g, t - k + i);
      ans.push_back({u, t - k + i});
    }
  }
}
void solve() {
  int n, u, v;
  cin >> n;
  vector<int> g[n];
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  T = 0;
  for (int i = 0; i < n; i++) T = max(T, (int)g[i].size());
  dfs(0, -1, g, 0);
  cout << ans.size() << "\n";
  for (pair<int, int>& i : ans) cout << i.first + 1 << " " << i.second << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
