Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

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

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

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int g[102][102];
int d[102], f[102];
int t = 0, n;

int dfs(int x){
    t++;
    //cout<<x<<" s: "<<t<<endl;
    for(int i=1; i<=n; i++){
        if(d[x] == 0) d[x] = t;
       
        if(g[x][i] == 1 && f[i] == 0){
            g[x][i] = 0;
            if(d[i] == 0){
                dfs(i);
                t++;
            }   
        }
        
        if(i == n && f[x] == 0){
            //   cout<<x<<" e: "<<t+1<<endl;
            f[x] = t+1;
        }
    }
    return 0;        
  
}

int main(){
    cin >> n;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            g[i][j] = 0;
        }
        d[i] = 0;
        f[i] = 0;
    }
    
    int u,k;
    for(int i=0; i<n; i++){
        cin>>u>>k;
        for(int j=0; j<k; j++){
            int v;
            cin>>v;
            g[u][v] = 1;
        }
    }

    for(int i=1; i<=n; i++){
        if(f[i]==0){
            dfs(i);
            t++;
        }
    }

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

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


int uma[101];
int n=1;
int sore;
int check;
int i;
int shika;
int ima = 1;
int deru=0;
int yagi=1;
int ushi[101];
int kaba[101];
int miti[101][101];
int eda[101][101];
int haji[1001];
int owari[1001];
int main(){
	cin >> shika;
	for (int i = 1; i < shika + 1; i++){
		cin >> uma[i];
		cin >> ushi[uma[i]];
		for (int j = 1; j < ushi[uma[i]] + 1; j++){
			cin >> miti[uma[i]][j];
			eda[uma[i]][miti[uma[i]][j]] = 1;
			eda[miti[uma[i]][j]][uma[i]] = 1;
		}
	}
	//cout << "??\?????????";
	//for (int test = 1; test < shika + 1; test++){ cout << uma[test]<<endl;}//test

	//???????????????????????????
	ima = 1;
	while (true){
		check = 0;
		if (deru == 3){ break; }
		if (deru == 1||deru==2){ deru = 0; }
		yagi = yagi + 1;
	//	cout << yagi << "yagi" << endl;
		if (haji[uma[ima]] == 0){
			haji[uma[ima]] = yagi;
		}
		while (true){
			if (deru > 0){ break; }
			if (eda[uma[ima]][miti[uma[ima]][n]] == 1&&haji[miti[uma[ima]][n]]==0&&owari[miti[uma[ima]][n]]==0){
				eda[uma[ima]][miti[uma[ima]][n]] = 2; 
				//cout << "idou" << ima << "to" << miti[uma[ima]][n] << endl;
				eda[miti[uma[ima]][n]][uma[ima]] = 2;
				ima = miti[uma[ima]][n];
				n = 1;
				break;
			}
			if (eda[uma[ima]][miti[uma[ima]][n]] == 0){
			//	cout << "ikidomari" << endl;
						owari[uma[ima]] = yagi;		
				//cout << "owari" << uma[ima] << yagi << owari[uma[ima]] << endl;
				n = 1;
			//	cout << eda[3][4] <<"shika" << shika <<endl;
				while (true){
					//cout << "edan" << uma[ima] << n << miti[n][uma[ima]] << eda[uma[ima]][miti[n][uma[ima]]] << endl;
					if (deru == 2||deru == 3){ break; }
					for (int sore = 1; sore < shika + 1; sore = sore + 1){
						if (eda[uma[ima]][miti[uma[ima]][sore]] == 1&&owari[miti[uma[ima]][sore]]==0){
							deru = 2;
							n = 1;
							//cout << ima << "move to" << miti[uma[ima]][sore] << endl;
							eda[uma[ima]][miti[uma[ima]][sore]] = 2;
							eda[miti[uma[ima]][sore]][uma[ima]] = 2;
							ima = miti[uma[ima]][sore];
							check = 1;
						}
					}for (int sore = 1; sore < shika + 1; sore = sore + 1){
						if (check==0&&eda[uma[ima]][sore] == 2){
							eda[uma[ima]][sore] = 3;
							eda[sore][uma[ima]] = 3;
							ima = sore;
							deru = 2;
							n = 1;
							//cout << "modoru" << endl;
							break;
						}
					}
					if (n>shika+1){
						for (int i = 1; i < shika + 1; i++){
							if (haji[uma[i]] == 0){
								ima = i;
								//cout << "warp to " << ima << endl;
								deru = 2;
								n = 1;
								break;
							}
							else if (i == shika){
								//cout << "shika" << shika << "i" << i << "shuryo" << endl;
								deru = 3;
								break;
							}
						}
					}
					n = n + 1;
				}
			}
			n = n + 1;
		}
	}
	for (int i = 1; i < shika + 1; i++){
		cout << uma[i] << " " << haji[uma[i]] << " " << owari[uma[i]] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX 105

int Mytime = 1;
int d[MAX], f[MAX];
struct Vertex {
	int degree;
	vector<int> adj;
	Vertex(int x = 0) {
		degree = x;
	}
};
vector<Vertex> v;

void DFS(int now) {
	if (d[now] != 0) // 已经搜索过了
		return;
	d[now] = Mytime;
	Mytime++;
	int count;
	for (count = 0; count < v[now].degree; count++) {
		DFS(v[now].adj[count]);
	}
	f[now] = Mytime;
	Mytime++;
}

int main(void) {
	int n, i, j;
	Vertex temp;
	v.push_back(temp);
	cin >> n;
	int u, k, ve;
	for (i = 1; i <= n; i++) {
		d[i] = f[i] = 0;
		cin >> u >> k;
		v.push_back(temp);
		v[i].degree = k;
		while (k--) {
			cin >> ve;
			v[u].adj.push_back(ve);
		}
	}
	for (i = 1; i <= n; i++) {
		DFS(i);
	}
	for (i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

}

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

using namespace std;
#define WHITE 0 //未到達
#define GLAY 1 //訪問中
#define BLACK 2 //訪問完了
#define INF 1000000001

int num_node;

int dfs(const vector<vector<int> > &adj_list, vector<int> &d, vector<int> &f,const int id, int counter){
    counter++;
    d[id] = counter;
    if(id!=0){
        for(int i = 0; i < adj_list[id].size(); i++){
            if(d[adj_list[id][i]] == INF){
                counter = dfs(adj_list,d,f,adj_list[id][i],counter);
        }
        }   
    }
    else{
        for(int i = 1; i < num_node + 1;i++){
            if(d[i]==INF){
                counter = dfs(adj_list,d,f,i,counter);
            }
        }
    }
    
    counter++;
    f[id] = counter;
    return counter;
}



int main(){
    int id, k, to;
    cin >> num_node;
    vector<vector<int> > adj_list(num_node+1);
    vector<int> color[num_node+1];
    vector<int> d(num_node+1,INF), f(num_node+1,INF);

    adj_list[0].push_back(1);
    for(int j = 0 ;j < num_node;j++){
        cin >> id >> k;
        for(int i =0;i < k; i++){
            cin >> to;
            adj_list[id].push_back(to);
        }    
    }
    
    dfs(adj_list, d, f, 0, -1);
    for(int i=1;i <= num_node; i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }

    return 0;
}