#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
vector<int> edges[N];
pair<int, int> ans[N];
int now = 1;
bool used[N];
void dfs(int v) {
  used[v] = true;
  vector<int> go;
  for (int i = 0; i < edges[v].size(); ++i) {
    if (!used[edges[v][i]]) {
      go.push_back(edges[v][i]);
      ans[edges[v][i]].first = now++;
      used[edges[v][i]] = true;
    }
  }
  ans[v].second = now++;
  for (int i = go.size() - 1; i >= 0; --i) {
    dfs(go[i]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int s1, s2;
    cin >> s1 >> s2;
    edges[s1 - 1].push_back(s2 - 1);
    edges[s2 - 1].push_back(s1 - 1);
  }
  ans[0].first = now++;
  dfs(0);
  for (int i = 0; i < n; ++i) {
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  }
  return 0;
}
