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

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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