#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
vector<int> v[501000];
int num = 0;
int l[501000], r[501000];
void dfs(int fa, int x) {
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] == fa) continue;
    dfs(x, v[x][i]);
  }
  l[x] = ++num;
  for (int i = v[x].size() - 1; i >= 0; i--) {
    if (v[x][i] == fa) continue;
    r[v[x][i]] = ++num;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0, 1);
  r[1] = 2 * n;
  for (int i = 1; i <= n; i++) cout << l[i] << " " << r[i] << endl;
}
