Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: // ???????????????????????¬?????¬????§£??¬?????\????????????
// ?????£??¨??????????????????????????£?????°???????????¨??????????????????????????????????????????????????£???

#include <cstdio>
#include <stack>
using namespace std;

#define start first
#define end second

static const int NOT   = false;	// ?????????
static const int WHITE = 1;		// ????¨????
static const int BLACK = 2;		// ?¨??????????
static const int N	   = 101;	// ?????§??°???????????????

int  n;						// ????????°
int  VisitedInfo[N];		// ?¨?????????±
bool Graph[N][N];			// ??°??????
pair< int, int > Time[N];	// ?¨???????????????¨?¨???????????????????

void dfs( int u );		// ??±???????????¢?´¢??¢??°
int  nextNode( int u ); // ?¬?????¨?????????????????????¢?????¢??°

int main()
{

	int u, k, v;	// u : ????????????, k : ??£??\?????????????????°, v : ??£??\?????????????????????

	// ?????????
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) Graph[i][j] = NOT;
		VisitedInfo[i] = WHITE;
	}

	scanf( "%d", &n );
	for( int i = 0; i < n; i++ ) {
		
		scanf( "%d %d", &u, &k );
		for( int j = 0; j < k; j++ ) {

			scanf( "%d", &v );
			Graph[u][v] = true;	// ??°?????????????????????
								//
			/*

				??? : Graph[1][2] = true; ??????1??????2???????????????
							 [3] = true;		  3???????????????
							 [4] = true;		  4???????????????

					 Graph[3][3] = true; ??????3??????3????????????(???????????????)???

					 Graph[4][5] = true; ??????4??????5???????????????(?????\???)
							 [6] = true;		  6???????????????

					 Graph[5][4] = true; ??????5??????4???????????????(?????\???)
							 [6] = true;		  6???????????????

					???1????????????

										 <????????°??????>
 
 										  1 2 3 4 5 6
 										-------------
 									  1 | 0 1 1 1 0 0		????????????????????????????????´???????????£???????????°???????????????????????????
 									  2 | 0 0 0 0 0 0		
 									  3 | 0 0 1 0 0 0		???????????? : ???????????????????????????????????????????????°????????????????????????????????????
 									  4 | 0 0 0 0 1 1		????????\??? : ????????°????????¨???????????????????????°?????????
 									  5 | 0 0 0 1 0 1		???????????? : ??????????????????????????£?????´??????????´???°??????????????????????????°?????????
 									  6 | 0 0 0 0 0 0
			*/
		}

	}

	dfs( 1 ); // ??????1????????±???????????¢?´¢????§?

	for( int i = 1; i <= n; i++ ) printf( "%d %d %d\n", i, Time[i].start, Time[i].end );

	return 0;

}

void dfs( int u )
{

	int  time = 1, pos, ppos;	// time : ??¢?´¢??????, pos : ?????¨?¨????????????????, ppos : ???????¨????????????????
	bool brkUpNodeFlg = false;	// brkUpNodeFlg : ????????????????????????????¨?????????????????????????????????????????????°
	stack< int > dfsInfo;		// ????????????

	// ??????????¨??????????????????????????????\
	// ?¨????????????¨??????
	dfsInfo.push( u );
	Time[u].start  = time;
	VisitedInfo[u] = BLACK;

	// ????????????????????????????????§?????????
	while( !dfsInfo.empty() ) {

		ppos = dfsInfo.top();	// ???????¨?????????????????????????????????????????????¨??????(???????????????????????????)

		if( !brkUpNodeFlg ) pos = nextNode( ppos );		// ??????????????¢?´¢????????????

		brkUpNodeFlg = false;

		// ???????????¨???????¨??????§?????£?????´???
		if( pos != 0 ) {
			if( VisitedInfo[pos] == WHITE ) {

				dfsInfo.push( pos );		// ?¨??????????????????????????????\
				Time[pos].start  = ++time;	// ?¨??????????????????¢?´¢???????????????????????????????????£??\
				VisitedInfo[pos] = BLACK;	// ?¨????????????¨??????

			}
		}
		// ???????????¨????????¨??????????¨????????????????????????£?????´???
		if( pos == 0 && VisitedInfo[ppos] != WHITE ){

			dfsInfo.pop();					// ?????????
			Time[ppos].end	  = ++time;		// ?¨????????????????????????¢?´¢???????????????????????????????????£??\
			VisitedInfo[ppos] = BLACK;		// ?¨????????????¨??????


		}

		// ????????????????????§?????????????¨?????????????????????¨????????´???
		if( dfsInfo.empty() ) {
			for( int i = 1; i <= n; i++ ) {
				if( VisitedInfo[i] == WHITE ) {

					pos = i;					// ????¨???????????????????????¬?????¨??????????????????¨??????
					dfsInfo.push( pos );		// ???????????\
					Time[pos].start  = ++time;	// ??????
					VisitedInfo[pos] = BLACK;	// ?¨??????????
					brkUpNodeFlg     = true;	// ???????????????????????¨????????????????????????????????°??????????????????
					break;

				}
			}
		}

	}

}

int nextNode( int now )
{

	// ?????¨?¨???????????????????????¨??????§????????????????¨??????§????????????????????£?????´?????????????????????
	// ?????¨???????????£?????´?????????0?????????
	for( int i = 1; i <= n; i++ ) {
		if( Graph[now][i] && VisitedInfo[i] == WHITE ) return i;
	}

	return 0;

}

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

struct Node{
	int color, d, f;
	queue<int> Q;
};

int main(){
	int n;
	cin >> n;
	Node node[n + 1];
	stack<int> move;
	for(int i = 1; i <= n; i++){
		int u, k, v;
		cin >> u >> k;
		node[u].color = WHITE;
		while(k--){
			cin >> v;
			node[u].Q.push(v);
		}
	}

	move.push(1);
	int tt = 1, p, next;
	node[1].color = GRAY;
	node[1].d = tt;
	tt++;

	while(!move.empty()){
		p = move.top();
		if(node[p].Q.empty()){
			node[p].color = BLACK;
			node[p].f = tt;
			move.pop();
			tt++;
		} else {
			next = node[p].Q.front();
			if(node[next].color == WHITE){
				move.push(next);
				node[next].color == GRAY;
				node[next].d = tt;
				tt++;
			} else {
				node[p].Q.pop();
			}
		}
	}

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