#include <bits/stdc++.h>
using namespace std;
vector<int> G[1000005];
int n, L[1000005], R[1000005], ind;
void dfs(int u, int pre) {
  for (int i = G[u].size() - 1; i >= 0; i--) {
    int v = G[u][i];
    if (v != pre) L[v] = ++ind;
  }
  R[u] = ++ind;
  for (auto v : G[u])
    if (v != pre) dfs(v, u);
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  L[1] = ++ind;
  dfs(1, 1);
  for (int i = 1; i <= n; i++) cout << L[i] << " " << R[i] << '\n';
}
