Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 100
//#define MAX_ 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = 0, f = 0;
};
Graph G[MAX];
int cou = 1;
void Depth(Graph *g)
{
	if (g->k >= 0) {
		if (g->d)
			return; 
		
		g->d = cou;
		++cou;
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			Depth(&G[*i]);
		}
		g->f = cou;
		++cou;
		
	}
}

int main(void)
{
	int n, u, xk, v;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &u, &xk);
		G[u - 1].id = u - 1;
		G[u - 1].k = xk;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &v);
			G[u - 1].node.push_back(v - 1);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (G[i].d == 0 && G[i].f == 0) 
			Depth(&G[i]);
		
	}
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", G[i].id + 1, G[i].d, G[i].f);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

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

//u に隣接するvを番号順に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if( M[u][v] ) return v; 
    }
    return NIL;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(S.size() != 0){
        int u = S.top();
        int v = next(u);
        if(v != NIL){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs_init(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    //未訪問のuを始点として深さ優先探索
    for(int u = 0; u < n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i = 0;i < n; i++){
        cout << i + 1 << " " << d[i]  << " " << f[i] << endl;
    }
}

int main(){
    cin >> n;
    int u, k, v;

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

    dfs_init();

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <utility>

using vvb = std::vector<std::vector<bool>>;

struct TimeStamp
{
    int discovered;
    int finished;
};

std::vector<TimeStamp> dfs(const vvb& edges)
{
    using namespace std;

    int time {1};
    const int n = edges.size();
    stack<int> st;
    vector<bool> reached(n);
    vector<TimeStamp> times(n);

    //すべての辺について行う
    for (int i = 0; i < n; ++i)
    {
        if (reached[i])
            continue;

        times[i].discovered = time++;
        st.push(i);
        
        //点iからつながるすべての辺を調べる
        while (!st.empty())
        {
            int top = st.top();
            for(int i = 0; i < n; ++i)
                if (!reached[i] && edges[top][i])
                {
                    reached[i] = true;
                    times[i].discovered = time++;
                    st.push(i);
                    break;
                }

            //その点からの探索候補がなければ前の点に戻る
            if (top == st.top())
            {
                times[top].finished = time++;
                st.pop();
            }
        }
    }

    return times;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    vvb edges(n, vector<bool>(n));

    //読み込み
    for (int i = 0; i < n; ++i)
    {
        int u, k;
        cin >> u >> k;

        for (int j = 0; j < k; ++j)
        {
            int v;
            cin >> v;
            edges[u - 1][v - 1] = true;
        }
    }

    auto times = dfs(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i + 1 << " " << times[i].discovered << " " << times[i].finished << endl;
    }
}

int main()
{
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
int p=0;
int d[200],f[200];
void dfs(const Graph &G, int v) {
    if (!seen[v]) d[v]=p+1;
    seen[v] = true; // v を訪問済にする
    p++;f[v]=p;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) {
            continue; // next_v が探索済だったらスルー
        }
        dfs(G, next_v); // 再帰的に探索
    }
    p++;f[v]=p;
}

int main() {
   int n;
   cin >> n;
   Graph G(n+1);
   for (int i=0; i<n; i++) {
       int u,k;
       cin >> u >> k;
       for (int j=0; j<k; j++) {
           int v;
           cin >> v;
           G[u].push_back(v);
       }
   }
   seen.assign(n+1,false);
   for (int i=1; i<n+1; i++) {
       if (!seen[i]) {
           dfs(G,i);
       }
   }
   for (int i=1; i<n+1; i++) {
       cout << i << " " << d[i] << " " << f[i] << endl;
   }
}