Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

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

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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;

}