#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
vector<int> G[maxn];
using pii = pair<int, int>;
pii ans[maxn];
int dfs(int u, int fa, int l, int r) {
  int num = 0;
  for (auto &v : G[u])
    if (v != fa) num++;
  ans[u] = {l, r + num + 1};
  int cnt = 1, nxt = ans[u].second;
  for (auto &v : G[u]) {
    if (v == fa) continue;
    nxt = dfs(v, u, ans[u].second - cnt, nxt);
    cnt++;
  }
  return nxt;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1, 1, 1);
  for (int i = 0; i < n; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
