#include <bits/stdc++.h>
using namespace std;
vector<int> G[500005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (register int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  int pos = 1;
  vector<pair<int, int> > res(n);
  function<void(int, int)> dfs = [&](int x, int f) {
    for (auto& y : G[x])
      if (y != f) res[y].first = pos++;
    res[x].second = pos++;
    reverse(G[x].begin(), G[x].end());
    for (auto& y : G[x])
      if (y != f) dfs(y, x);
  };
  res[0].first = pos++;
  dfs(0, -1);
  for (register int i = 0; i < n; ++i) {
    cout << res[i].first << " " << res[i].second << endl;
  }
  return 0;
}
