#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5;
int n, st[MAXN + 5], fn[MAXN + 5], cur = 1;
vector<int> ms[MAXN + 5];
void dfs(int first, int p) {
  for (vector<int>::reverse_iterator i = ms[first].rbegin();
       i != ms[first].rend(); ++i) {
    int o = *i;
    if (o == p) continue;
    st[o] = cur++;
  }
  fn[first] = cur++;
  for (vector<int>::iterator i = ms[first].begin(); i != ms[first].end(); ++i) {
    int o = *i;
    if (o == p) continue;
    dfs(o, first);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int first, second;
    cin >> first >> second;
    ms[first].push_back(second);
    ms[second].push_back(first);
  }
  st[1] = cur++;
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) {
    cout << st[i] << ' ' << fn[i] << endl;
  }
  return 0;
}
