Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #if 0
以前の反省を踏まえて、idの扱いを早いうちに決めてよかった
#endif

#include <iostream>
#include <vector>
using namespace std;

int curtime = 0, INF = 10000 * 100000 + 100;
struct result
{
    int reach_time;
    int back_time;
};
result res[110];
struct nodeData
{
    int id;
    vector<int> nodes;
};
vector<nodeData> dataSet;

// idはは1から
// for文は1から回す
vector<int> getNodes(int id)
{
    return dataSet[id - 1].nodes;
}

void dfs(int cur)
{
    // curの訪問時刻を記録
    curtime += 1;
    res[cur].reach_time = curtime;
    vector<int> nodes = getNodes(cur);
    for (int i = 0; i < nodes.size(); i++)
    {
        int node = nodes[i];
        if (res[node].reach_time == INF)
        {
            // 未訪問の場合
            dfs(node);
        }
    }
    curtime += 1;
    res[cur].back_time = curtime;
}

int main()
{
    // 初期化
    int /* 頂点数 */ n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        nodeData temp;
        temp.id = i;
        int id, /* 出次数 */ appear;
        cin >> id >> appear;
        for (int j = 1; j <= appear; j++)
        {
            int node;
            cin >> node;
            temp.nodes.push_back(node);
        }
        dataSet.push_back(temp);
        res[i].reach_time = INF;
    }

    // 処理
    for (int i = 1; i <= n; i++)
    {
        if (res[i].reach_time == INF)
        {
            dfs(i);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << res[i].reach_time << " " << res[i].back_time << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#define MAX_N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int n, u, k, v;
int Adj[MAX_N][MAX_N];
int d[MAX_N], f[MAX_N], color[MAX_N];
int tt;

void initialize(){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			Adj[i][j] = 0;
		}
	}
}

void check_adj(){
	Adj[u][v] = 1;
}

void dfs_visit(int u){
	color[u] = GRAY;
	d[u] = ++tt;
	for(int v = 0; v < n; v++){
		if(Adj[u][v] == 0) continue;
		if(color[v] == WHITE){
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs(){
	tt = 0;
	for(int i = 0; i < n; i++) color[i] = WHITE;
	for(int i = 0; i < n; i++){
		if(color[i] == WHITE) dfs_visit(i);
	}
	for(int i = 0; i < n; i++){
		printf("%d %d %d\n", i + 1, d[i], f[i]);
	}
}

/* void print_adj(){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cout << Adj[i][j];
			if(j == n - 1) cout << endl;
			else cout << " ";
		}
	}
} */

int main(void){
	cin >> n;
	initialize();
	for(int i = 0; i < n; i++){
		cin >> u;
		u--;
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> v;
			v--;
			check_adj();
		}
	}
	dfs();
	//print_adj();

	return 0;
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int time_stamp = 0;
std::vector<int> d;
std::vector<int> f;

void dfs(std::vector<std::vector<int> > &G, std::vector<bool> &is_searched, int i){
	if(is_searched[i]){
		//time++;
		return;
	}
	is_searched[i] = true;
	time_stamp++;
	d[i] = time_stamp;

	for(int j = 0; j < G[i].size(); j++){
		dfs(G, is_searched, G[i][j]);
	}
	time_stamp++;
	f[i] = time_stamp;
	return;
}

int main(int argc, char **argv){
	int n, u, k, v;
	std::vector<std::vector<int> > G;
	std::vector<bool> is_searched;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	G.resize(n);
	is_searched.resize(n, false);
	d.resize(n, 0);
	f.resize(n, 0);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> u >> k;
#else
		std::cin >> u >> k;
#endif
		G[u - 1].resize(k);
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> v;
#else
			std::cin >> v;
#endif
			G[u - 1][j] = v - 1;
		}
	}

	for(int i = 0; i < n; i++){
		dfs(G, is_searched, i);
	}

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

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

//次の点へ移動とかする関数
int next_point(int point, int (&a)[100][100], int (&num)[100], int (&back)[100], int time[100][2]){
	int next = a[point][num[point]]-1;
	
	//行先が探索終了しているしている場合、pointを返す
	if(a[next][1] == 0 && time[next][1] != 0){
		a[point][1] -= 1;
		return point;
	}
	
	back[next] = point;
	a[point][1] -= 1;
	return next;
}

int main(void){
	int a[100][100];
	int back[100];				//back[]:現在いる点の始点
	int time[100][2];	//time[i][0]:発見時刻,time[i][1]:探索終了時間
	int m, time_now=1, point=0;	//point:現在探索している点
	int num[100];
	
	cin >> m;
	
	for(int i=0; i<m;i++){
		cin >> a[i][0];
		cin >> a[i][1];
		
		for(int j=2; j<a[i][1]+2; j++){
			cin >> a[i][j];
		}
	}

	//ここまで入力
	//ここから↓
	
	//numを2に初期化
	for(int i=0; i<100; i++){
		num[i] = 2;
		time[i][0] = INT_MAX;
	}
	
	time[0][1] = -1;
	
	time[point][0] = time_now++;
	while(time[0][1] == -1){
		
		//矢印が出ていない場合
		if(a[point][1] == 0){
			time[point][1] = time_now++;	//探索終了時刻を決定
			point = back[point];	//始点へ移動
		}
		
		//矢印が出ている場合
		if(a[point][1] != 0){
			point = next_point(point, a, num, back, time);
			num[back[point]] += 1;
			if(time[point][0] > time_now) time[point][0] = time_now++;	//探索開始時刻を決定
		}
	}
	
	//出力
	for(int i=0; i<m; i++){
		cout << i+1 << " " << time[i][0] << " " << time[i][1] << "\n";
	}
	
	return 0;
}