#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> res(500009);
long long counter = 1;
void dfs_tree(long long idx, long long par, vector<vector<long long>> &adj) {
  for (auto i : adj[idx]) {
    if (i != par) {
      res[i].first = counter++;
    }
  }
  res[idx].second = counter++;
  reverse((adj[idx]).begin(), (adj[idx]).end());
  for (auto i : adj[idx]) {
    if (i != par) {
      dfs_tree(i, idx, adj);
    }
  }
}
int main() {
  long long(n);
  scanf("%lld", &(n));
  ;
  vector<vector<long long>> adj(n);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  };
  res[0].first = counter++;
  dfs_tree(0, -1, adj);
  for (long long i = 0; i < (n); i++) {
    printf("%lld %lld\n", res[i].first, res[i].second);
  }
  return 0;
}
