#include <bits/stdc++.h>
using namespace std;
const int N = 5e+5 + 20;
std::vector<int> v[N];
int l[N], r[N];
int used[N];
int pos;
void solve(int cur, int par) {
  for (auto x : v[cur]) {
    if (x != par) {
      l[x] = pos++;
    }
  }
  r[cur] = pos++;
  reverse(v[cur].begin(), v[cur].end());
  for (auto x : v[cur]) {
    if (x != par) {
      solve(x, cur);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  l[1] = 1;
  pos = 2;
  solve(1, -1);
  for (int i = 1; i <= n; ++i) {
    printf("%d %d\n", l[i], r[i]);
  }
  return 0;
}
