#include <bits/stdc++.h>
using namespace std;
int A[1000005], B[1000005], poin;
vector<int> V[1000005], VV[1000005];
void dfs(int u, int p) {
  for (auto v : V[u]) {
    if (v != p) {
      VV[u].push_back(v);
      dfs(v, u);
    }
  }
  A[u] = ++poin;
  for (int i = VV[u].size() - 1; i >= 0; i--) {
    B[VV[u][i]] = ++poin;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, n2;
  cin >> n;
  n2 = n;
  while (--n2) {
    int u, v;
    cin >> u >> v;
    V[u].push_back(v);
    V[v].push_back(u);
  }
  dfs(1, -1);
  B[1] = ++poin;
  for (int i = 1; i <= n; i++) {
    cout << A[i] << ' ' << B[i] << endl;
  }
}
