#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69;
const int mod = 1e9 + 7;
long long n, m, mx, ind, ans, len, x, y, a, b, c, t, k, T, w;
int be[N], en[N], fix[N], R;
vector<int> gr[N];
void dfs(int x) {
  fix[x] = 1;
  en[x] = R + gr[x].size() - (x != 1) + 1;
  R = en[x];
  int k = 1;
  for (int i = 0; i < gr[x].size(); i++) {
    int to = gr[x][i];
    if (fix[to]) continue;
    be[to] = en[x] - k;
    k++;
    dfs(to);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  be[1] = 1;
  R = 1;
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cout << be[i] << " " << en[i] << endl;
  }
}
