#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
vector<int> p[N];
int tot, f[N], l[N], r[N];
void dfs(int x) {
  int ss = p[x].size() - (x != 1);
  int ct = tot = r[x] = tot + ss + 1;
  for (auto& i : p[x])
    if (i != f[x]) {
      l[i] = --ct;
      f[i] = x;
      dfs(i);
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (auto i = (2); i <= (n); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    p[x].push_back(y);
    p[y].push_back(x);
  }
  l[1] = tot = 1;
  dfs(1);
  for (auto i = (1); i <= (n); ++i) printf("%d %d\n", l[i], r[i]);
}
