#include <bits/stdc++.h>
using namespace std;
const int maxn = 200605;
int head[maxn], num_edge;
struct Edge {
  int next, to;
} ed[maxn * 2];
void add(int from, int to) {
  ed[++num_edge].next = head[from];
  ed[num_edge].to = to;
  head[from] = num_edge;
}
int fa[maxn];
int cnt = 0, top = 0;
struct {
  int p, t;
} ans[1000605];
inline void print(int point, int tim) { ans[++cnt] = {point, tim}; }
int T;
int deg[maxn];
void dfs1(int now, int tim, int fa = 0) {
  print(now, tim);
  int t = tim;
  for (int i = head[now]; i; i = ed[i].next) {
    int to = ed[i].to;
    if (to == fa) continue;
    if (tim == T && t > deg[now]) tim = T - deg[now], print(now, tim);
    if (tim == deg[now] && t <= deg[now]) tim = 0, print(now, tim);
    dfs1(to, ++tim, now);
    print(now, tim);
  }
  if (t - 1 >= 0 && tim != t - 1) print(now, t - 1);
}
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while ((c < '0' || c > '9') && c ^ '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
int main() {
  int n;
  n = read();
  for (int i = 1; i < n; i++) {
    int u, v;
    u = read();
    v = read();
    add(u, v), add(v, u);
    deg[u]++, deg[v]++;
  }
  for (int i = 1; i <= n; i++) T = max(T, deg[i]);
  dfs1(1, 0);
  cout << cnt << "\n";
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", ans[i].p, ans[i].t);
  return 0;
}
