#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next;
} net[500039 << 1];
int n, tot, head[500039], siz[500039], son[500039], L[500039], R[500039];
void add(int u, int v) {
  net[++tot] = (edge){v, head[u]}, head[u] = tot;
  net[++tot] = (edge){u, head[v]}, head[v] = tot;
}
void dfs(int pos, int pre) {
  siz[pos] = son[pos] = 1;
  for (int a = head[pos]; a; a = net[a].next) {
    if (net[a].to != pre) {
      dfs(net[a].to, pos);
      siz[pos] += siz[net[a].to];
      son[pos]++;
    }
  }
}
void solve(int pos, int pre, int l, int r) {
  L[pos] = l, R[pos] = r, l = r;
  for (int a = head[pos]; a; a = net[a].next) {
    if (net[a].to != pre) {
      solve(net[a].to, pos, l - 1, r + son[net[a].to]);
      l--, r += siz[net[a].to] * 2 - 1;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int a = 1, b, c; a < n; a++) {
    scanf("%d%d", &b, &c);
    add(b, c);
  }
  dfs(1, 0);
  solve(1, 0, 1, son[1] + 1);
  for (int a = 1; a <= n; a++) {
    printf("%d %d\n", L[a], R[a]);
  }
  return 0;
}
