#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
int num[100005], stp = -1;
vector<pair<int, int> > output;
int ans = 0;
void dfs(int u, int p) {
  num[u] = ++stp;
  output.push_back({u, stp});
  if (edges[u].size() == 1 && u != 1) {
    output.push_back({u, stp - 1});
    return;
  }
  if (stp == ans) {
    stp = num[u] - 1 - (int)edges[u].size() + 1;
    output.push_back({u, stp});
  }
  int cnt = 0;
  for (int v : edges[u]) {
    if (v == p) continue;
    dfs(v, u);
    ++cnt;
    output.push_back({u, stp});
    if (u != 1 && stp == ans) {
      stp = num[u] - 1 - (int)edges[u].size() + cnt + 1;
      output.push_back({u, stp});
    }
  }
  if (u != 1 && stp != num[u] - 1) {
    output.push_back({u, stp = num[u] - 1});
  }
  ++stp;
}
int main() {
  int n;
  scanf("%d", &n);
  if (n == 1) {
    printf("1\n1 0\n");
    return 0;
  }
  for (int i = (1); i <= (n - 1); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  for (int i = (1); i <= (n); i++) ans = max(ans, (int)edges[i].size());
  dfs(1, -1);
  printf("%d\n", (int)output.size());
  for (auto u : output) {
    printf("%d %d\n", u.first, u.second);
  }
  return 0;
}
