#include <bits/stdc++.h>
using namespace std;
vector<int> vec[500005];
int l[500005], r[500005], cnt;
void dfs(int a, int f) {
  int i, j, b;
  j = vec[a].size();
  for (i = j - 1; i >= 0; i--) {
    b = vec[a][i];
    if (b == f) continue;
    l[b] = ++cnt;
  }
  r[a] = ++cnt;
  for (i = 0; i < j; i++) {
    b = vec[a][i];
    if (b == f) continue;
    dfs(b, a);
  }
}
int main() {
  int i, j, n, m, a, b;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  l[1] = ++cnt;
  dfs(1, -1);
  for (i = 1; i <= n; i++) {
    printf("%d %d\n", l[i], r[i]);
  }
  return 0;
}
