#include <bits/stdc++.h>
using namespace std;
vector<int> a[550000];
int l[550000], r[550000], last[550000], size[550000];
int n, x, y, tot = 0, cnt = 0;
void find(int x, int fa) {
  for (int k = a[x].size() - 1; k >= 0; k--) {
    int y = a[x][k];
    if (y != fa) {
      ++cnt;
      l[y] = cnt;
    }
  }
  r[x] = ++cnt;
  for (int k = 0; k < a[x].size(); k++) {
    int y = a[x][k];
    if (y != fa) {
      find(y, x);
    }
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  l[1] = 1;
  cnt = 1;
  find(1, -1);
  for (int i = 1; i <= n; i++) printf("%d %d\n", l[i], r[i]);
  return 0;
}
