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 <bits/stdc++.h>

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != n-1) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

bool adj[105][105];
bool vis[105];
struct node{
	int ft;
	int rt;
};
node v[105];

int n;
int cnt;

void dfs (int cur )
{
	cnt++;
	vis[cur] = true;	
	v[cur].ft = cnt;
	for (int u = 1; u <= n; u++ ){
		if (!vis[u] && adj[cur][u] )
			dfs (u );
	} // end for
	cnt++;
	v[cur].rt = cnt;
}

int main()
{
	memset (adj, false, sizeof (adj ) );
	memset (vis, false, sizeof (vis ) );

	ios_base::sync_with_stdio(0);
	cin >> n;

	rep (i, n ) v[i].ft = 0, v[i].rt = 0;

	rep (i, n ){
		int v, k;
		cin >> v >> k;
		while (k-- ){
			int u; cin >> u;
			adj[v][u] = true;
		} // end rep
	} // end rep
	cnt = 0;
	dfs (1 );	

	for (int i = 1; i <= n; i++ ){
		cout << i << ' ' << v[i].ft << ' ' << v[i].rt << endl;
	} // end for
	
	return 0;
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
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; }
const int INF = 1000000000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
bool E[101][101];
vector<bool> seen;
typedef pair<int, int> P;
int D[101];
int F[101];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

void dfs_search(int u) {
    //出発点を訪問済みにする＆行きのタイムスタンプを記録
    int v;

    color[u] = 1;
    D[u] = ++find_time;
    //cout << u+1 << " " << color[u] << " " << endl;
    for (v = 1; v <= N; v++) {
        //出発点からvへの辺があるか
        if (!E[u][v]) continue;
        //辺がある&&未訪問なら発見した頂点を出発点にして再帰
        if (color[v] == 0) dfs_search(v);
    }
    //今回訪問した頂点より深い未訪問の頂点がない時にその頂点を完了する。
    color[u] = 2;
    F[u] = ++find_time;
}

void dfs() {
    int u;
    find_time = 0;
    for (int i = 0; i < N; i++) color[i] = 0;
    for (u = 1; u <= N; u++) {
        //未訪問のuを出発点にしてDFS
        if (color[u] == 0 || color[u] == 1) dfs_search(u);
    }
    //出力
    for (int i = 1; i <= N; i++) {
        cout << i << " " << D[i] << " " << F[i] << endl;
    }
}

int main() {
    //boolで辺を管理
    cin >> N;
    int u, k;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            E[i][j] = false;
        }
        D[i] = 0;
        F[i] = 0;
    }

    //辺の配列E[][]において、falseは無辺、trueは有辺を表す。
    //有向グラフなのでE[i][j]のみ(無向だとE[j][i]も)
    for (int i = 1; i <= N; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            //v--;
            //u--;
            E[u][v] = true;
        }
    }

    dfs();

}