Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

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;

}