Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

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

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

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

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

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

#define S 100
#define BLACK 2
#define WHITE 0
#define GRAY 1

int n,a[S][S];
int cnd[S],d[S],f[S],T=0;
int nt[S];

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

void visit(int r){
    for(int i=0;i<n;i++)nt[i]=0;
    stack<int>st;
    st.push(r);
    cnd[r]=GRAY;
    d[r]=++T;

    while(!st.empty()){
        int u=st.top();
        int v=next(u);
        if(v!=-1){
            if(cnd[v]==WHITE){
                cnd[v]=GRAY;
                d[v]=++T;
                st.push(v);
            }
        }else{
            st.pop();
            cnd[u]=BLACK;
            f[u]=++T;
        }
    }
}

void outp(){
    for(int i=0;i<n;i++){
        cnd[i]=WHITE;
        //nt[i]=0;
    }

    for(int j=0;j<n;j++){
        if(cnd[j]==WHITE)visit(j);
    }
    for(int k=0;k<n;k++){
        cout<<k+1<<" "<<d[k]<<" "<<f[k]<<endl;
    }
}

int main(){
    int u,k,J,i,j;
    cin>>n;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)a[i][j]=0;
    }
    for(i=0;i<n;i++){
        cin>>u>>k;
        for(j=0;j<k;j++){
            cin>>J;
            a[u-1][J-1]=1;
        }
    }
    outp();
    return 0;
}

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

int t=0,k,n;
int gone[100+10]={},before[100+10]={},a[100+10][100+10]={};

void dfs(int cur){
    if(gone[cur]!=1){
        t+=1;
        cerr << "visiting " << cur << " at " << t << endl;
        gone[cur]=1;
    }
    for(int m=1;m<=n;m++){
        if(a[cur][m]==1){
            if(gone[m]==0){
                dfs(m);
            }
        }
    }
    t+=1;
    cerr << "complete " << cur << " at " << t << endl;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        int u,p;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> p;
            a[i][p]=1;
        }
    }
    for(int q=1;q<=n;q++){
        if(gone[q]!=1) dfs(q);
    }
}

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