#include <bits/stdc++.h>
using namespace std;
int n, m[2 * 500007], curr, l[500007], r[500007];
vector<long long> a[500007];
void dfs(int v, int par) {
  for (auto to : a[v])
    if (to != par) m[++curr] = to;
  m[++curr] = v;
  for (int i = a[v].size() - 1; i >= 0; --i) {
    int to = a[v][i];
    if (to != par) dfs(to, v);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int v1, v2;
    cin >> v1 >> v2;
    a[v1].push_back(v2);
    a[v2].push_back(v1);
  }
  m[1] = 1;
  curr = 1;
  dfs(1, -1);
  for (int i = 1; i <= 2 * n; ++i) {
    if (l[m[i]] == 0) l[m[i]] = i;
    r[m[i]] = i;
  }
  for (int i = 1; i <= n; ++i) cout << l[i] << ' ' << r[i] << endl;
  return 0;
}
