#include <bits/stdc++.h>
using namespace std;
const int N = 500100;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
vector<int> e[N];
int l[N], r[N], now;
void dfs(int u, int fa) {
  for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); ++it) {
    if (fa == *it) continue;
    l[*it] = ++now;
  }
  r[u] = ++now;
  int k = e[u].size();
  reverse(e[u].begin(), e[u].end());
  for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); ++it) {
    if (fa == *it) continue;
    dfs(*it, u);
  }
}
int main() {
  int n = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    e[u].push_back(v);
    e[v].push_back(u);
  }
  l[1] = ++now;
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d %d\n", l[i], r[i]);
  return 0;
}
