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) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

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

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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

	dfs(vertexId(1), 0, 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++: #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;
}