#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
void files(string problem) {
  if (fopen((problem + ".in").c_str(), "r")) {
    freopen((problem + ".in").c_str(), "r", stdin);
    freopen((problem + ".out").c_str(), "w", stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen(in, "r")) {
    freopen(in, "r", stdin);
  } else
    cerr << "Warning: Input file not found" << endl;
}
int n;
int l[Sz], r[Sz];
int pt[Sz];
int sz[Sz];
vector<int> g[Sz];
void dfs(int v, int pr, int pos) {
  sz[v] = 1;
  for (int to : g[v]) {
    if (to != pr) {
      dfs(to, v, pos);
      sz[v] += sz[to];
      pos += sz[to] * 2 - 1;
    }
  }
  pt[pos++] = v;
  l[v] = pos - 1;
  for (int i = (int)(g[v].size()) - 1; i >= 0; i--) {
    int to = g[v][i];
    if (to != pr) {
      pt[pos++] = to;
      r[to] = pos - 1;
    }
  }
}
int main() {
  Read_rap();
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1, 1);
  r[1] = 2 * n;
  for (int i = 1; i <= n; i++) {
    cout << l[i] << ' ' << r[i] << endl;
  }
  return 0;
}
