Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define MAXN 100
int n, timecount = 1;
int ans[MAXN][MAXN];
int d[MAXN], f[MAXN]; // d[i]はdを最初に発見した時刻,f[i]は調べ終わった時刻
bool is_reach[MAXN];

int dfs(int p);

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = -1;
        f[i] = -1;
        is_reach[i] = false;
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans[i][j] = 0;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int tmp;
            cin >> tmp;
            ans[u-1][tmp-1] = 1;
        }
    }
//    for (int i = 0; i < n; i++) {
//        for (int j = 0; j < n; j++) {
//            if (j == n-1) cout << ans[i][j];
//            else cout << ans[i][j] << " ";
//        }
//        cout << endl;
//    }
    int start = 0;
    while (1) {
        dfs(start);
        int i;
//        printf("%d search end\n", start);
        for (i = 0; i < n; i++) {
            if (f[i] == -1) {
                start = i;
                break;
            }
        }
        if (i == n) break;
//        printf("next: %d\n", start);
    }
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

int dfs(int p)
{
    int ret = 0, count = 1;
    is_reach[p] = true;
    if (d[p] == -1) d[p] = timecount++;
    for (int i = 0; i < n; i++) {
        if (ans[p][i] == 1 && is_reach[i] == false && p != i) {
            dfs(i);
        }
    }
    if (f[p] == -1) f[p] = timecount;
    timecount++;
    return 0;
}

C++: /*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> first_order;
vector<int> second_order;

void dfs(const Graph &G, int v, int &ptr) {
    first_order[v] = ptr++;
    seen[v]        = true;

    for(const auto &next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, ptr);
    }

    second_order[v] = ptr++;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    Graph G(n + 1); // 1-indexed
    rep(i, n) {
        int v, k;
        cin >> v >> k;
        rep(i, k) {
            int to_v;
            cin >> to_v;
            G[v].push_back(to_v);
        }
    }
    // 頂点1スタート
    seen.assign(n + 1, false);
    first_order.resize(n + 1);
    second_order.resize(n + 1);
    int ptr = 1;
    REP(i, 1, n + 1) {
        if(!seen[i]) dfs(G, i, ptr);
    }

    REP(i, 1, n + 1) {
        cout << i << " " << first_order[i] << " " << second_order[i] << endl;
    }
}

C++: #include <iostream>
using namespace std;

void search(int i,int *table, int n, int *d, int *f, int *cnt){
	
	++(*cnt);
	d[i] = *cnt;
	for(int k=0;k<n;++k){
		table[k*n+i] = 0;
	}
	for(int j=0;j<n;++j){
		if(table[i*n+j]){
			search(j,table,n,d,f,cnt);
		}
	}
	
	++(*cnt);
	f[i] = *cnt;
}

int main() {
	int n,*table,*d,*f, cnt;
	
	cin>>n;
	table = new int[n*n];
	d = new int[n];
	f = new int[n];
	
	for(int i=0;i<n;++i){
		int u,k,v;
		cin>>u>>k;
		for(int j=0;j<k;++j){
			cin>>v;
			table[(u-1)*n+v-1]=1;
		}
	}
	cnt = 0;
	
	while(true){
		int rest = 0;
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				if(table[i*n+j]){
					rest = 1;
					break;
				}
			}
			if(rest){
				search(i,table,n,d,f,&cnt);
				break;
			}
		}
		if(!rest){
			break;
		}
	}
	
	for(int i=0;i<n;++i){
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

vector<pii> visit;
int order=1;

void dfs(vector<vi> &G, int v){
    visit[v].first=order;
    order++;
    for(auto nv: G[v]){
        if(visit[nv].first != -1) continue;
        dfs(G, nv);
    }
    visit[v].second=order;
    order++;
}

int main(){
    int n; cin >> n;
    vector<vi> G(n+1);
    visit.assign(n+1, {-1,-1});
    for(int i=0; i<n; i++){
        int u, k; cin >> u >> k;
        for(int j=0; j<k; j++){
            int v; cin >> v;
            G[u].push_back(v);
        }
    }
    for(int i=1; i<=n; i++){
        if(visit[i].first != -1) continue;
        dfs(G, i);
    }
    for(int i=1; i<=n; i++){
        cout << i << " " << visit[i].first << " " << visit[i].second << endl;
    }
    return 0;
}