#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 5e5 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   int n, id, a, b;   vector<int> v[MAX], ans[MAX];   void dfs(int nw, int par) {     for (auto i : v[nw]) {       if (i == par) continue;       ans[i].push_back(++id);     }     ans[nw].push_back(++id);     reverse(v[nw].begin(), v[nw].end());     for (auto i : v[nw]) {       if (i == par) continue;       dfs(i, nw);     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i)       cin >> a >> b, v[a].push_back(b), v[b].push_back(a);     ans[1].push_back(++id);     dfs(1, 0);     for (int i = 1; i <= n; ++i) cout << ans[i][0] <<     << ans[i][1] <<   n ;     return 0;   }   