#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const int32_t SMALL = LONG_MIN >> 1;
const int32_t BIG = LONG_MAX >> 1;
const int32_t MAXN = 500001;
int32_t st[MAXN], en[MAXN];
vector<int32_t> g[MAXN];
int32_t n, cur;
void dfs(int32_t u, int32_t p) {
  for (int32_t v : g[u])
    if (v != p) st[v] = ++cur;
  en[u] = ++cur;
  reverse(g[u].begin(), g[u].end());
  for (int32_t v : g[u])
    if (v != p) dfs(v, u);
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int32_t i = 1; i < n; i++) {
    int32_t u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  st[1] = ++cur;
  dfs(1, -1);
  for (int32_t i = 1; i <= n; i++) cout << st[i] << " " << en[i] << endl;
}
