Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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

}