#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long m) {
  long long r = 1;
  a %= m;
  for (; b; b >>= 1) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
  }
  return r;
}
const int inf = 0x7fffffff;
const int maxn = 5e5 + 10;
vector<int> g[maxn];
int l[maxn], r[maxn];
int ml[maxn], d[maxn];
int n;
void dfs(int u, int pre, int x) {
  if (u == 1) {
    r[u] = 2 * n;
    l[u] = 2 * n - d[u] - 1;
  } else {
    l[u] = ml[pre] - d[u];
    r[u] = l[pre] + x;
  }
  ml[u] = l[u];
  int xx = 1;
  for (int i = 0; i < (int)(g[u]).size(); i++) {
    int v = g[u][i];
    if (v == pre) continue;
    dfs(v, u, xx);
    ml[u] = min(ml[u], ml[v]);
    xx++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    d[u]++;
    d[v]++;
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) cout << l[i] << " " << r[i] << endl;
  return 0;
}
