#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[500005];
vector<pair<int, int> > ans;
int l, r;
void dfs(int node, int ata, int solkisim) {
  int sagkisim = adj[node].size() + r;
  int yer = sagkisim - 1;
  r = sagkisim;
  for (int ch : adj[node]) {
    if (ch == ata) continue;
    dfs(ch, node, yer--);
  }
  ans[node] = make_pair(solkisim, sagkisim);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ans.resize(n);
  l = 1;
  r = (int)adj[0].size() + 2;
  ans[0] = make_pair(l, r);
  int yer = r - 1;
  for (int ch : adj[0]) {
    dfs(ch, 0, yer--);
  }
  for (int i = 0; i < n; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
