#include <bits/stdc++.h>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = int(1e9 + 7);
const int tam = 500010;
vector<int> G[tam];
int L[tam], R[tam];
int n;
int minL[tam];
void dfs(int v, int p, int minVal) {
  int children = G[v].size() - (p != -1);
  L[v] = minVal - children;
  minL[v] = L[v];
  int cnt = 0;
  for (int u : G[v]) {
    if (u == p) continue;
    R[u] = L[v] + (++cnt);
    dfs(u, v, minL[v] - 1);
    minL[v] = min(minL[v], minL[u]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  R[0] = 2 * n;
  dfs(0, -1, 2 * n - 1);
  for (int i = 0; i < n; ++i) {
    cout << L[i] << ' ' << R[i] << '\n';
  }
  return 0;
}
