#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g;
vector<long long> ls, rs, used;
long long from;
void dfs(long long pos, long long par) {
  long long children = g[pos].size() - (par == -1 ? 0 : 1);
  rs[pos] = from + children;
  long long lp = rs[pos] - 1;
  from = rs[pos] + 1;
  for (int i = 0; i < g[pos].size(); ++i) {
    long long nxt = g[pos][i];
    if (nxt == par) {
      continue;
    }
    ls[nxt] = lp--;
    dfs(nxt, pos);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  g = vector<vector<long long>>(n);
  ls = vector<long long>(n);
  rs = vector<long long>(n);
  used = vector<long long>(2 * n + 2, 0);
  for (int i = 0; i < n - 1; ++i) {
    long long fr, to;
    cin >> fr >> to;
    fr--;
    to--;
    g[fr].push_back(to);
    g[to].push_back(fr);
  }
  ls[0] = 1;
  from = 2;
  dfs(0, -1);
  for (int i = 0; i < n; ++i) {
    cout << ls[i] << " " << rs[i] << "\n";
  }
  return 0;
}
