Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

vector<vector<int>> G(101, vector<int>(0));
vector<int> c(101, 0);
vector<int> d(101, 0);
vector<int> f(101, 0);

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int t = 0;
void dfs(int i) {
    if(c[i]) return;
    c[i] = 1;
    d[i] = ++t;
    for(auto e : G[i])
        dfs(e);
    f[i] = ++t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b, c;
    cin >> n;
    rep(i, n) {
        cin >> a >> b;
        rep(j, b) {
            cin >> c;
            G[a].push_back(c);
        }
    }
    rep(i, 1, n + 1) dfs(i);

    rep(i, 1, n + 1) cout << i << " " << d[i] << " " << f[i] << "\n";
}

C++: 	#include<stdio.h>
	int k[101]={0},d[101]={},f[101]={};
	int v[101][101]={0};
	int cur;
	void dfs(int id){
		if(d[id]!=0){
			return;
			}
			cur++;
			if(d[id]==0){
				d[id]=cur;
			}
			for(int i=0;i<k[id];i++){
				dfs(v[id][i]);
			}
			cur++;
			f[id]=cur;
			return;
		}
		int main(void){
		int n=0,u=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d",&u);
			scanf("%d",&k[u]);
			for(int j=0;j<k[u];j++){
				scanf("%d",&v[u][j]);//uからいけるj個目のノードがv[u][j]
			}
		}
		for(int i=1;i<n;i++){
		if(d[i]==0){
		dfs(i);
		}
		}
		for(int i=1;i<=n;i++){
			printf("%d %d %d\n",i,d[i],f[i]);
		}
	return(0);
}

C++: // 深さ優先探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 100
// 値の定義
const int EXIST = 1;
const int NO_EXIST = 0;

const int WHITE = 0;// 未訪問
const int GRAY = 1; // 訪問中
const int BLACK = 2;// 訪問完了

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];

// 各頂点の訪問状態を保持する配列
int color[MAX_N + 1];

// 発見時刻と完了時刻を保持する構造体
typedef struct
{
    int start_time;
    int end_time;
}SearchTime;

SearchTime st_SearchTime[MAX_N + 1];
int search_T = 0;

void depthFirstSearch(int now_vertex, int vertex_num);

int main(void)
{
    int n, u, num, v_num;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        color[i] = WHITE;

        for(int j = 0; j < MAX_N + 1; j++)
        {
            // 配列の初期化
            ary_graph[i][j] = NO_EXIST;
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> u;
        cin >> num;

        // 0オリジンにする
        u--;

        for(int j = 0; j < num; j++)
        {
            // 隣接点を記憶する
            cin >> v_num;

            // 0オリジンにする
            v_num--;
            ary_graph[u][v_num] = EXIST;
        }
    }

    // 深さ優先探索を実施
    for(int i = 0; i < n; i++)
    {
        if( color[i] == WHITE )
        {
            depthFirstSearch(i, n);
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        printf("%d %d %d\n", i + 1, st_SearchTime[i].start_time, st_SearchTime[i].end_time);
    }

    return 0;
}

// 深さ優先探索を実施する関数
// now_vertex : 現在の頂点のNo.
// next_vertex : 次の頂点のNo.
// vertex_num : グラフの頂点数
void depthFirstSearch(int now_vertex, int vertex_num)
{
    // 訪問中
    color[now_vertex] = GRAY;

    // 発見時刻の設定
    search_T++;
    st_SearchTime[now_vertex].start_time = search_T;

    for(int i = 0; i < vertex_num; i++)
    {
        if( color[i] == WHITE
            && ary_graph[now_vertex][i] == EXIST )
        {
            depthFirstSearch(i, vertex_num);
        }
    }

    // 訪問完了
    color[now_vertex] = BLACK;

    // 終了時刻の設定
    search_T++;
    st_SearchTime[now_vertex].end_time = search_T;

    return;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>

#define N 100

using namespace std;

int n;
int unvisited=0,visited=1,comp_visited=2;
int M[N][N],state[N],nt[N];
int d[N],f[N],t;

int next(int u){
	for(int v=nt[u];v<n;v++){
		nt[u]=v+1;
		if(M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r){
	for(int i=0;i<n;i++){
		nt[i]=0;
	}
	stack<int> s;
	s.push(r);
	state[r]=visited;
	t++;
	d[r]=t;
	
	while(!s.empty()){
		int u=s.top();
		int v=next(u);
		if(v!=-1){
			if(state[v]==unvisited){
				state[v]=visited;
				t++;
				d[v]=t;
				s.push(v);
			}
		}
		else{
			s.pop();
			state[u]=comp_visited;
			t++;
			f[u]=t;
		}
	}
}

void dfs(){
	for(int i=0;i<n;i++){
		state[i]=unvisited;
		nt[i]=0;
	}
	t = 0;
	for(int u=0;u<n;u++){
		if(state[u]==unvisited) dfs_visit(u);
	}
	for(int i=0;i<n;i++){
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}
}

int main(){
	int u,k,v;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(int j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v]=1;
		}
	}
	dfs();
}

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

int now_time = -1, time_stamp_d[101]{}, time_stamp_f[101]{};
int vertices_num;
std::vector<int> dest[101];
void search(int);

int main()
{
	int vertex_tmp, dest_num, dest_tmp;

	std::cin >> vertices_num;
	for (int i = 1; i <= vertices_num; ++i)
	{
		std::cin >> vertex_tmp >> dest_num;
		for (int j = 0; j < dest_num; ++j)
		{
			std::cin >> dest_tmp;
			dest[vertex_tmp].push_back(dest_tmp);
		}
		dest[0].push_back(i);
	}
	
	search(0);

	for (int i = 1; i <= vertices_num; ++i)
	{
		std::cout << i << " " << time_stamp_d[i] << " " << time_stamp_f[i] << std::endl;
	}

	return 0;
}

void search(int now_place)
{
	time_stamp_d[now_place] = ++now_time;
	for (auto e : dest[now_place])
	{
		if (time_stamp_d[e]) continue;
		search(e);
	}
	time_stamp_f[now_place] = ++now_time;
	return;
}