Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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