#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 5e5 + 123;
struct node {
  vector<node*> adj;
  node* p;
  int eldiff;
  int erdiff;
  int start;
  int end;
  inline void set_start_end(int& pl, int& pr) {
    start = --pl;
    pr += -eldiff + 1;
    end = pr;
    pr += erdiff;
  }
  void dfs1(node* pa) {
    p = pa;
    for (auto sn : adj) {
      if (sn == p) {
        continue;
      }
      sn->dfs1(this);
    }
    if (p == nullptr) {
      int x = 0, y = 0;
      set_start_end(x, y);
    } else {
      set_start_end(p->eldiff, p->erdiff);
    }
  }
  void dfs2() {
    if (p == nullptr) {
      start = 1;
      end = start + -eldiff + 1;
    } else {
      start += p->end;
      end += p->end;
    }
    for (auto sn : adj) {
      if (sn == p) {
        continue;
      }
      sn->dfs2();
    }
  }
  inline void print() { cout << start << ' ' << end << '\n'; }
} nodes[N];
int n, x, y;
int main() {
  ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    nodes[x].adj.push_back(nodes + y);
    nodes[y].adj.push_back(nodes + x);
  }
  node& root = nodes[1];
  root.dfs1(nullptr);
  root.dfs2();
  for (int i = 1; i <= n; i++) {
    nodes[i].print();
  }
}
