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
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			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
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	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 <iostream>
#include <stack>
using namespace std;

static const int MAX_NUM = 101;

static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void DSF(int* matrix, int num)
{
    int i, j;
    int ttime = 0;
    int stime[MAX_NUM+1] = {0};
    int etime[MAX_NUM+1] = {0};
    int state[MAX_NUM+1] = {0};
    stack<int> S;
    int target, next;
    int *tmp;

    for (j = 1; j <= num; j++) {
    if (state[j] != NO_VISIT) {
        continue;
    }
    S.push(1);
    ++ttime;
    stime[1] = ttime;
    state[1] = NOW_VISIT;

    while (S.empty() == false) {
        target = S.top();
        for (i = 1; i <= num; i++) {
            tmp = matrix + MAX_NUM * target + i;
            if ((*tmp == 1) && (state[i] == NO_VISIT)) {
                *tmp = 2;
                S.push(i);
                ++ttime;
                stime[i] = ttime;
                state[i] = NOW_VISIT;
                break;
            }
        }

        if (i == num + 1) {
            S.pop();
            ++ttime;
            etime[target] = ttime;
            state[target] = END_VISIT;
        }
    }
    }

    for (i = 1; i <= num; i++) {
        printf("%d %d %d\n", i, stime[i], etime[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int elem;
    int nume;
    int tmp;
    int matrix[MAX_NUM][MAX_NUM] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d %d", &elem, &nume);
        for (j = 0; j < nume; j++) {
            scanf("%d", &tmp);
            matrix[elem][tmp] = 1;
        }
    }

    DSF(&matrix[0][0], num);

    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

typedef struct node_{
    public:
        queue<int> next;//次の添字(0始まりに変換している)
        int visited;
        int k;//出次数
        int u;//頂点番号
        int d;//発見時刻
        int f;//完了時刻
        node_(){};
}* node;

vector<node> readGraph(int n){
    vector<node> graph;
    for(int i = 0; i < n; i++){
        int u;
        int k;
        scanf("%d %d", &u, &k);
        node nd = new node_;
        nd -> k = k;
        nd -> u = u;
        nd -> visited = 0;
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d", &v);
            v--;//0始まりに
            nd -> next.push(v);
        }
        graph.push_back(nd);
    }
    return graph;
}

void depthFirstSearch(vector<node> graph, int n){
    stack<int> st;
    int cnt = 0;//時刻
    for(int i = 0; i < n; i++){
        if(graph[i] -> visited == 1){
            
        }else{
            st.push(i);
            cnt++;
            graph[i] -> d = cnt;
            graph[i] -> visited = 1;
            while(st.empty() != 1){
                node nd = graph[st.top()];
                if(nd -> next.empty() == 1){
                    cnt++;
                    nd -> f = cnt;
                    st.pop();
                }else{
                    node nx = graph[nd -> next.front()];
                    if(nx -> visited == 1){
                        nd -> next.pop();
                    }else{
                        cnt++;
                        nx -> d = cnt;
                        nx -> visited = 1;
                        st.push(nd -> next.front());
                        nd -> next.pop();
                    }
                }
                /*
                if(graph[st.top()] -> next.empty() == 1){//訪れた点のnextがない//nextがemptyだとvisitedにならない
                    cnt++;
                    graph[st.top()] -> f = cnt;
                    st.pop();
                }else if(graph[graph[st.top()] -> next.front()] -> visited == 1){
                    graph[st.top()] -> next.pop();
                }else{
                    cnt++;
                    graph[graph[st.top()] -> next.front()] -> d = cnt;
                    graph[graph[st.top()] -> next.front()] -> visited = 1;
                    st.push(graph[st.top()] -> next.front());
                    graph[st.top()] -> next.pop();
                }
                */
            }
        }
    }
}

void printTestGraph(vector<node> graph, int n){
    for(int i = 0; i < n; i++){
        node nd = graph[i];
        printf("node[%d] u = %d k = %d\n", i, nd -> u, nd -> k);
        for(int j = 0; j < nd -> k; j++){
            printf("%d ", nd -> next.front());
            nd -> next.pop();
        }
        printf("\n");
    }
}

void printResult(vector<node> graph, int n){
    for(int i = 0; i < n; i++){
        node nd = graph[i];
        printf("%d %d %d\n", nd -> u, nd -> d, nd -> f);
    }
}

int main(){
    //printf("start\n");
    int n;
    scanf("%d", &n);
    vector<node> graph = readGraph(n);
    //printf("readGraph() end\n");
    //printTestGraph(graph, n);//ここまでうまくいってる
    depthFirstSearch(graph, n);
    //printf("depthFirstSearch() end\n");
    printResult(graph, n);
    return 0;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

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

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

int main(){
    int u, v, k, i, j;
    
    scanf("%d", &n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++) M[i][j] = 0;
    }
    
    for(i=0; i<n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    
    return 0;
}