#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int MOD = 1000000007;
ll INF = 1LL << 62;
ld EPS = 1e-8;
ld PI = acos(-1);
int N;
vector<int> adj[500010];
vector<int> child[500010];
int lft[500010], rgt[500010];
int pos = 0;
void dfs(int p, int pp) {
  for (int i : adj[p]) {
    if (i != pp) {
      child[p].push_back(i);
      dfs(i, p);
    }
  }
}
void dfs1(int p) {
  for (int i : child[p]) lft[i] = pos++;
  rgt[p] = pos++;
  for (int i = (int)child[p].size() - 1; i >= 0; i--) dfs1(child[p][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(0, -1);
  lft[0] = pos++;
  dfs1(0);
  for (int i = 0; i < N; i++) {
    cout << lft[i] + 1 << " " << rgt[i] + 1 << "\n";
  }
  return 0;
}
