#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, k, s, t, l[N], r[N], tot;
vector<int> e[N];
void dfs(int u, int fa) {
  for (int v : e[u])
    if (v != fa) l[v] = ++tot;
  r[u] = ++tot;
  for (int i = e[u].size() - 1; i >= 0; --i)
    if (e[u][i] != fa) dfs(e[u][i], u);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> s >> t;
    e[s].push_back(t);
    e[t].push_back(s);
  }
  l[1] = 1;
  tot = 1;
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) cout << l[i] << ' ' << r[i] << endl;
}
