#include <bits/stdc++.h>
using namespace std;
const int maxm = 5e5 + 5;
int l[maxm], r[maxm], tot;
vector<int> g[maxm];
int n;
void dfs(int x, int fa) {
  int len = g[x].size();
  for (int i = len - 1; i >= 0; i--) {
    int v = g[x][i];
    if (v == fa) continue;
    l[v] = ++tot;
  }
  r[x] = ++tot;
  for (int i = 0; i < len; i++) {
    int v = g[x][i];
    if (v == fa) continue;
    dfs(v, x);
  }
}
signed main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  l[1] = ++tot;
  dfs(1, -1);
  for (int i = 1; i <= n; i++) {
    printf("%d %d\n", l[i], r[i]);
  }
  return 0;
}
