Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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

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

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

}