#include <bits/stdc++.h>
using namespace std;
int n, avail;
int L[500011], R[500011];
vector<int> adj[500011];
void solve(int v, int p) {
  int deg = (int)adj[v].size();
  if (p != v) deg--;
  R[v] = avail + deg;
  avail = R[v];
  int cnt = 1;
  for (int u : adj[v]) {
    if (u == p) continue;
    avail++;
    L[u] = R[v] - cnt;
    cnt++;
    solve(u, v);
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  L[0] = 1;
  avail = 2;
  solve(0, 0);
  for (int i = 0; i < n; i++) cout << L[i] << " " << R[i] << endl;
  return 0;
}
