#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 3;
vector<vector<int>> g;
int t = 1, in[N], out[N];
void dfs(int node, int p = -1) {
  for (int u : g[node])
    if (u != p) in[u] = ++t;
  out[node] = ++t;
  for (int i = g[node].size() - 1; i >= 0; i--) {
    int u = g[node][i];
    if (u != p) dfs(u, node);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  g.assign(n + 1, vector<int>());
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  in[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; i++) cout << in[i] << " " << out[i] << "\n";
  return 0;
}
