Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>

#define MAX 120
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

static const int N =120;

int n;//頂点数
int T;//時刻
int d[MAX];//発見時刻
int f[MAX];//終了時刻
int color[MAX];//判別
int M[N][N];

void dfs_v(int u){
   
    color[u] = GRAY;
    T++;
    d[u] = T;
    for(int v=0; v<n; v++){
        if(M[u][v]==0){
            continue;
        }
        if(color[v]==WHITE){
            dfs_v(v);
        }
    }
    
    color[u]= BLACK;
    T++;
    f[u] = T;
}

void dfs(){
    for(int j=0; j<n; j++){
        color[j] = WHITE;
        
    }
    T = 0;
    
    for(int j=0; j<n; j++){
        if(color[j] == WHITE){
            dfs_v(j);
        }
    }
    
    for(int j=0; j<n; j++){
        printf("%d %d %d\n", j+1, d[j], f[j]);
    }
}

int main(){
    
    
    //cin >> n;
    
    int Adj[MAX];
    int u, k, v;
    
    scanf("%d", &n);
    
    for(int b=0; b<n; b++){
        for(int i=0; i<n; i++){
        M[b][i] = 0;
        }
    }
    
    
    
    for(int j=0; j<n; j++){
        //cin >> u >>k;
        scanf("%d %d", &u, &k);
        u--;
        for(int a=0; a<k; a++){
            /*cin >> v;
            Adj[v] = 1;
            
            if(Adj[v] != 0){
            M[u][v] = 1;
            }*/
            
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    return 0;
}