#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 2e9;
int n, deg[N], u, v, res = 0, par[N];
set<int> val[N];
vector<int> edge[N];
vector<pair<int, int> > ans;
void dfs(int u, int t, int ret) {
  ans.push_back(make_pair(u, t));
  val[u].erase(t);
  if (u != 1) val[u].erase(ret);
  int lst = -1, rem = 0;
  for (int i = 0; i < (int)edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == par[u]) continue;
    par[v] = u;
    lst = v;
    rem++;
  }
  for (int i = 0; i < (int)edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == par[u]) continue;
    if (t >= res) {
      t = ret - rem;
      if (u == 1) t = *val[u].begin();
      val[u].erase(t);
      ans.push_back(make_pair(u, t));
    }
    rem--;
    dfs(v, t + 1, t);
    t = t + 1;
    val[u].erase(t);
    ans.push_back(make_pair(u, t));
  }
  if (u != 1 && t != ret) {
    t = ret;
    val[u].erase(t);
    ans.push_back(make_pair(u, t));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
    deg[u]++, deg[v]++;
  }
  res = deg[1];
  for (int i = 2; i <= n; i++) {
    res = max(res, deg[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= min(deg[i] + 2, res); j++) {
      val[i].insert(j);
    }
  }
  par[1] = 1;
  dfs(1, 0, 0);
  cout << (int)ans.size() << "\n";
  for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
