#include <bits/stdc++.h>
std::vector<int> g[100005];
int enter[100005], change[100005];
int in[100005];
int vis[100005];
struct Element {
  int x, y;
  Element(int x, int y) : x(x), y(y) {}
};
std::vector<Element> ans;
void solve(int u, int T) {
  vis[u] = 1;
  ans.push_back(Element(u, enter[u]));
  int x = enter[u], end = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (!vis[v]) {
      if (x == T) {
        x = change[u], end = 1;
        ans.push_back(Element(u, change[u]));
      }
      enter[v] = x + 1;
      if (x + in[v] <= T) {
        change[v] = x;
        solve(v, T);
      } else {
        change[v] = T - in[v];
        solve(v, T);
      }
      ans.push_back(Element(u, x + 1));
      x++;
    }
  }
  if (u != 1 && !end) ans.push_back(Element(u, change[u]));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
    in[u]++, in[v]++;
  }
  int T = 0;
  for (int i = 1; i <= n; i++) T = T > in[i] ? T : in[i];
  enter[1] = 0;
  solve(1, T);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].x, ans[i].y);
  return 0;
}
