#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)2e9;
const long long mod = 1000000007;
long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long powmod(long long a, long long p) {
  long long ans = 1;
  a %= mod;
  while (p) {
    if (p & 1) ans *= a;
    p /= 2;
    a *= a;
    ans %= mod;
    a %= mod;
  }
  return ans;
}
long long mdinv(long long a) { return powmod(a, mod - 2); }
const long long N = 5e5 + 20;
vector<long long> adj[N];
long long first[N], second[N];
long long no = 1;
void dfs(long long i, long long p) {
  for (long long v : adj[i]) {
    if (v != p) first[v] = ++no;
  }
  second[i] = ++no;
  for (long long ind = (long long)(adj[i].size()) - 1; ind >= 0; ind--) {
    long long v = adj[i][ind];
    if (v != p) dfs(v, i);
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a, b;
  for (long long i = 0; i < (long long)n - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  first[1] = 1;
  dfs(1, 0);
  for (long long i = 1; i <= n; i++)
    cout << first[i] << " " << second[i] << "\n";
}
