#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5 + 5;
vector<int> edges[MAXN];
int n;
int l[MAXN];
int r[MAXN];
int cur = 2;
void go(int node, int p = 0) {
  int tt = 0;
  for (int i : edges[node]) {
    if (i == p) continue;
    tt++;
  }
  r[node] = cur + tt;
  int val = cur + tt - 1;
  for (int i : edges[node]) {
    if (i == p) continue;
    l[i] = val;
    val--;
  }
  cur = r[node] + 1;
  for (int i : edges[node]) {
    if (i == p) continue;
    go(i, node);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  l[1] = 1;
  go(1);
  for (int i = 1; i <= n; i++) cout << l[i] << ' ' << r[i] << '\n';
  return 0;
}
