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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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 <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 <sstream>
int used[101]={0};
int V[101][101]={0};
int first[101]={0};
int finish[101]={0};
int t=1;
int n;

void search(int i){
  first[i]=t++;
  used[i]++;
  for(int j=0;j<n;j++){
    if(V[i][j]==1 and used[j]==0){
      search(j);
    }
  } 
  finish[i]=t++;
}



int main () {
  int k;
  int u1,u;
  std::cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      V[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    std::cin>>u1>>k;
    for(int j=0;j<k;j++){
      std::cin>>u;
      V[u1-1][u-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(used[i]==0){
      search(i);
    }
  }
  for(int i=0;i<n;i++){
    std::cout<<i+1<<" "<<first[i]<<" "<<finish[i]<<"\n";
  }


  return 0;
}