Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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;
}