#include <bits/stdc++.h>
using namespace std;
vector<int> g[500010];
pair<int, int> ans[500010];
int nextVal = 2;
void dfs(int node, int prev) {
  int cantNeighbors = g[node].size();
  if (node != prev) cantNeighbors--;
  for (auto it = g[node].begin(); it != g[node].end(); it++)
    if (*it != prev) ans[*it].first = nextVal++;
  ans[node].second = nextVal++;
  for (auto it = g[node].rbegin(); it != g[node].rend(); it++)
    if (*it != prev) dfs(*it, node);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = (0); i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans[0].first = 1;
  dfs(0, 0);
  for (int i = (0); i < (n); i++)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  return 0;
}
