#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5 + 5;
vector<int> ad[mxN];
int l[mxN];
int r[mxN];
int sz[mxN];
void dfs(int node, int par) {
  int cur = r[node];
  sz[node] = 0;
  for (int child : ad[node]) {
    if (child == par) continue;
    l[child] = --cur;
    r[child] = l[child] + 2 * sz[node] + ad[child].size() + 1;
    dfs(child, node);
    sz[node] += sz[child];
  }
  sz[node]++;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    ad[u].push_back(v);
    ad[v].push_back(u);
  }
  l[1] = 1;
  r[1] = ad[1].size() + 2;
  dfs(1, -1);
  for (int i = 1; i <= n; i++) cout << l[i] << " " << r[i] << "\n";
  return 0;
}
