Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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;
}