#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > v;
vector<long long int> ans1, ans;
long long int id = 1;
void dfs(long long int s, long long int p) {
  for (auto u : v[s]) {
    if (u != p) {
      dfs(u, s);
    }
  }
  ans[s] = id;
  id++;
  for (long long int i = v[s].size() - 1; i >= 0; i--) {
    if (v[s][i] == p) {
      continue;
    }
    ans1[v[s][i]] = id;
    id++;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << " " << 2 << endl;
    return 0;
  }
  v.resize(n + 1);
  ans1.resize(n + 1);
  ans.resize(n + 1);
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0);
  ans1[1] = id;
  for (long long int i = 1; i <= n; i++) {
    cout << ans[i] << " " << ans1[i] << endl;
  }
  return 0;
}
