Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
vi conne[100];
vb is_visited(100,false);
int n;
int t=1;;
int f[100];
int d[100];
void dfs(int i){
    if(!is_visited[i]){
        d[i]=t++;
        is_visited[i]=true;
    }
    for(int itr:conne[i]){
       if(is_visited[itr])continue;
       dfs(itr);
    }
    f[i]=t++;
}
int main( ){
    cin>>n;
    rep(i,0,n){
        int id;
        cin>>id;
        id--;
        int num; cin>>num;
        rep(j,0,num){
            int in; cin>>in;
            in--;
            conne[id].push_back(in);
        }
        sort(conne[id].begin(),conne[id].end());
    }
    rep(i,0,n){
        if(is_visited[i]==false)dfs(i);
    }
    rep(i,0,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX 101
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, t, top, u[MAX], color[MAX], M[MAX][MAX], S[MAX], d[MAX], f[MAX];

int next(int u){
  for(int i=1; i<=n; i++){
    if(M[u][i] == 1 && color[i] == WHITE){
      return i;
    }
  }
  return NIL;
}

void dfs(int u){
  int v;
  S[++top] = u;
  color[u] = GRAY;
  d[u] = ++t;

  while(top > 0){
    u = S[top];
    v = next(u);
    if(v != NIL){
      color[v] = GRAY;
      d[v] = ++t;
      S[++top] = v;
    }else{
      top--;
      color[u] = BLACK;
      f[u] = ++t;
    }
  }
}

void dfs_init(){
  for(int i=0; i<MAX; i++){
    color[u[i]] = WHITE;
  }

  t = 0;
  top = 0;
}

int main(void){
  int k, m;
  cin >> n;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(int i=0; i<n; i++){
    cin >> u[i] >> k;
    for(int j=0; j<k; j++){
      cin >> m;
      M[u[i]][m] = 1;
    }
  }

  dfs_init();
  for(int i=0; i<n; i++){
    if(d[u[i]] == 0) dfs(u[i]);
  }

  for(int i=0; i<n; i++){
    cout << u[i] << " " << d[u[i]] << " " << f[u[i]] << endl; 
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,step=0,fdepth[105],sdepth[105];
bool visit[105],c[105][105];
void dfs(int node){
    step++;
    fdepth[node]=step;
    for(int i=1;i<=n;i++)
        if(!visit[i]&&c[node][i]){
            visit[i]=1;
            dfs(i);
        }
    step++;
    sdepth[node]=step;
}
int main(){
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    while(cin>>n){
        memset(fdepth,0,sizeof(fdepth));
        memset(sdepth,0,sizeof(sdepth));
        memset(c,0,sizeof(c));
        memset(visit,0,sizeof(visit));
        int parent,num,son;
        step=0;
        for(int i=0;i<n;i++){
            cin>>parent>>num;
            while(num--){
                cin>>son;
                c[parent][son]=1;
            }
        }
        visit[1]=1;
        dfs(1);
        for(int i=1;i<=n;i++)
            cout<<i<<' '<<fdepth[i]<<' '<<sdepth[i]<<'\n';
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

#define MAX 100

int d[MAX], f[MAX], t = 0, M[MAX][MAX] = {}, n;

void dfs(){
    int seen[MAX] = {};
    rep(i, n){
        if(seen[i]) continue;
        stack<int> todo;
        seen[i] = 1;
        todo.push(i);
        t++;
        d[i] = t;
        while(!todo.empty()){
            int m = todo.top();
            rep(j, n + 1){
                if(j == n){
                    todo.pop();
                    t++;
                    f[m] = t;
                    break;
                }
                if(M[m][j] && !seen[j]){
                    todo.push(j);
                    t++;
                    d[j] = t;
                    seen[j] = 1;
                    break;
                }
            }
        }
    }
}

int main(){
    cin >> n;
    rep(i, n){
        int l, p;
        cin >> l >> p;
        rep(j, p){
            int q;
            cin >> q;
            M[l - 1][q - 1] = 1;
        }
    }
    dfs();
    
    rep(i, n){
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return 0;
}