Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

C++: #include<iostream>
#include<cstring>
#include<stack>
using namespace std;

int M[101][101], sta[101], en[101], n;
stack<int>S;

void dfs()
{
	int id, op;
	bool have;
	id = op = 1;

	while (true)
	{ 
		if (sta[id] == 0)          
		{
			S.push(id);
			sta[id] = op++;
		}

		have = false;
		
		for (int pid = 1; pid <= n; pid++)
		{
			if (M[id][pid] == 1 && sta[pid] == 0)     
			{
				id = pid;
				have = true;
				break;
			}
		}

		if (!have)
		{
			S.pop();
			en[id] = op++;

			if (!S.empty())
				id = S.top();
			else
			{
				for (int i = 1; i <= n; i++)
				{
					if (sta[i] == 0)
					{
						id = i;
						break;
					}		
				}			
			}
		}

		if (op > 2 * n)
			break;
	}
}

int main()
{
	int id, pid, k;

	memset(M, 0, sizeof(M));
	memset(sta, 0, sizeof(sta));
	memset(en, 0, sizeof(en));

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> id >> k;

		for (int j = 1; j <= k; j++)
		{
			cin >> pid;
			M[id][pid] = 1;
		}
	}

	dfs();

	for (int i = 1; i <= n; i++)
		cout << i << " " << sta[i] << " " << en[i] << endl;

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> G;
vector<bool> seen;
vector<int> d,f;
void DFS(int v,int& time){
    d[v]=time++;
    seen[v]=1;
    for(auto p:G[v]){
        if(seen[p])continue;
        DFS(p,time);
    }
    f[v]=time++;
}
int main(){
    scanf("%d",&n);
    seen=vector<bool>(n);
    d=f=vector<int>(n);
    G=vector<vector<int>>(n,vector<int>());
    for(int i=0;i<n;i++){
        int v,k;scanf("%d%d",&v,&k);
        for(int j=0;j<k;j++){
            int a;scanf("%d",&a);
            G[v-1].push_back(a-1);
        }
    }
    for(int i=0;i<n;i++) sort(G[i].begin(),G[i].end());
    int time=1;
    for(int i=0;i<n;i++){
        if(!seen[i])DFS(i,time);
    }
    for(int i=0;i<n;i++){
        printf("%d %d %d\n",i+1,d[i],f[i]);
    }
    return 0;
}