#include <bits/stdc++.h>
using namespace std;
const int nsz = 5e5;
int n, rt = 1, t, l[nsz + 5], r[nsz + 5];
vector<int> g[nsz + 5];
void dfs(int u = rt, int p = rt) {
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == p) continue;
    l[v] = ++t;
  }
  r[u] = ++t;
  for (int i = g[u].size() - 1; i >= 0; --i) {
    int v = g[u][i];
    if (v == p) continue;
    dfs(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  l[rt] = ++t;
  dfs();
  for (int u = 1; u <= n; ++u) {
    cout << l[u] << ' ' << r[u] << '\n';
  }
}
