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 <iostream>
#include <cstdio>
using namespace std;

int n, t, G[101][101], S[101], T[101];

void dfs(int p) {
    if (S[p] != 0) return;
    S[p] = ++t;
    for (int i = 0; i < n; i++)
        if (G[p][i] == 1)
            dfs(i);

    T[p] = ++t;
}


int main(void) {
    int u, k, v, s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u - 1][v - 1] = 1;
        }
    }

    t = 0;
    for (int i = 0; i < n; i++)
        dfs(i);

    for (int i = 0; i < n; i++)
        printf("%d %d %d\n", i + 1, S[i], T[i]);

    return 0;
}

C++: #include<iostream>

using namespace std;

int A[101][100];//データを入れる配列
int d[101];
int f[101];
int t = 1;//time

int Depth(int n){
    if((f[n] != 0)){//既に探索が終了していたら、その節点は飛ばす
        return 0;
    }
    if(d[n] == 0){//はじめて通る節点だったら、dに時間を記録
        d[n] = t;
        t++;
    }
    if((A[n][0] != 0)){//隣接点が1つ以上ある場合は以下のループに入る
        for(int i=1; i<=A[n][0]; i++){
            //if(A[n][i] == n){//自分自身に返ってくるノードだったら、
            //    f[A[n][i]] = t;
            //    t++;
            //    return 0;
            //}
            if((A[n][i] != n) && (d[A[n][i]] == 0)){
                Depth(A[n][i]);
            }
        }
    }
    f[n] = t;
    t++;
}

int main(){
    int n, num;
    cin >> n;
    for(int k=1; k<=n; k++){
        d[k] = 0;
        f[k] = 0;
    }
    for(int i=1; i<=n; i++){
        cin >> num;
        cin >> A[i][0];
        for(int j=1; j<=A[i][0]; j++){
            cin >> A[i][j];
        }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u){//ntってなに？？現在地？
	for( int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for ( int i =0; i<n;i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;

	while( !S.empty() ) {
		int u = S.top();
		int v = next(u);
		if(v != -1){
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs() {
	for (int i = 0; i<n;i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

	for(int u = 0; u<n;u++) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	for ( int i =0; i<n ;i++) {
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}

int main(){
	int u, k, v;

	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 >> k;
		u--;
		for ( int j = 0; j < k;j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}

	}

	dfs();
	return 0;
}

C++: #include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void dfs(int now, vector<vector<int>>& path, vector<int>& find, vector<int>& finish, int& time) {
		find[now] = time++;
		REP(i, path[now].size()) {
			int t = path[now][i];
			if (find[t] < 0) {
				dfs(t, path, find, finish, time);
			}
		}
		finish[now] = time++;
	}

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<vector<int>> path(n);
		REP(i, n) {
			int u, k;
			cin >> u >> k;
			u--;
			REP(j, k) {
				int v;
				cin >> v;
				v--;
				path[u].push_back(v);
			}
		}
		vector<int> visit(n, 0);
		vector<int> find(n, -1);
		vector<int> finish(n, -1);
		int time = 1;
		REP(i, n) {
			if (find[i] < 0) {
				dfs(i, path, find, finish, time);
			}
		}
		REP(i, n) {
			put(i + 1, find[i], finish[i]);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0; u < n; u++) color[u] = WHITE;
    tt = 0;
    for(u = 0; u < n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0; u < n; u++){
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}

int main(){
    int u, v, k, i, j;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++) M[i][j] = 0;
    }
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(j = 0; j < k; j++){
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}