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++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

using Graph = vector<vector<int>>;
Graph G;

vector<int> d, f;

int dfs(int v, int t) {
    if(d[v]==0) d[v]=t;
    int res = t;
    for(const auto nv: G[v]) {
        if (d[nv]) continue;
        res = dfs(nv, res+1);
    }
    return f[v] = ++res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    G.resize(n);
    rep(i, n) {
        int x, k; cin >> x >> k;
        x--;
        rep(j, k) {
            int v; cin >> v; v--;
            G[x].push_back(v);
        }
    }

    d.assign(n, 0); f.assign(n, 0);

    int cur = 1;
    rep(i, n) {
        if (!d[i]) {
            cur = dfs(i, cur);
            cur++;
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

using ll = long long;
using namespace std;

/* initialize */
int color[100], nt[100], d[100], f[100], tt;
int A[100][100];
int n;

int next(int u){
    for (int v = nt[u]; v < n; ++v) {
        nt[u] = v + 1;
        if( A[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r){
    for (int i = 0; i < n; ++i) nt[i] = 0;
    stack<int> S;
    S.push(r);
    color[r] = 1;
    d[r] += ++tt;

    while (!S.empty()){
        int u = S.top();
        int v = next(u);
        if (v != -1){
            if (color[v] == 0){
                color[v] = 1;
                d[v] = ++tt;
                S.push(v);
            }
        } else{
            S.pop();
            color[u] = 2;
            f[u] = ++tt;
        }
    }
}
void dfs(){
    for (int i = 0; i < n; ++i) {
        color[i] = 0;
    }
    tt = 0;

    for (int u = 0; u < n; ++u) {
        if (color[u] == 0) dfs_visit(u);
    }
    for (int i = 0; i < n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
}
/* main */
int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) A[i][j] = 0;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            A[u-1][v-1] = 1;
        }
    }

    dfs();
    return 0;
}

C++: #include<cstdio>
#define WHITE 0
#define GRAY  1
#define BLACK 2

void InitializeBoolMatrix(int nmbr_of_rows, int nmbr_of_columns, bool mtrx[][100]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_columns; ++column)
			mtrx[row][column] = false;
	}
}

void ListToMatrix(int number_of_vertices, bool mtrx[][100]){
	int vertex_from, vertex_to, degree_out;	
	for (int vertex_i = 0; vertex_i < number_of_vertices; ++vertex_i) {
		scanf("%d %d", &vertex_from, &degree_out);
		vertex_from--; //0?????????????????????
		for (int vertex_out_i = 0; vertex_out_i < degree_out; ++vertex_out_i) {
			scanf("%d", &vertex_to);
			vertex_to--; //0?????????????????????
			mtrx[vertex_from][vertex_to] = true;
		}
	}
}

bool adjmtrx[100][100];

void BuildAdjacencyMatrix(int n){
	InitializeBoolMatrix(n, n, adjmtrx);
	ListToMatrix(n, adjmtrx);
}

int color[100];
int time;
int discoveredtime[100];
int finishedtime[100];

void Dfs(int present_vertex, int n){
	int pv = present_vertex;
	color[pv] = GRAY;
	discoveredtime[pv] = ++time;
	for(int v = 0;v < n;v++){
		if(adjmtrx[pv][v] && color[v] == WHITE){
			Dfs(v, n);
		}
	}
	color[pv] = BLACK;
	finishedtime[pv] = ++time;
}

void DfsInit(int n){
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;
	time = 0;
}

int main(){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	int n = number_of_vertices;
	BuildAdjacencyMatrix(n);
	DfsInit(n);
	for (int vertex_i = 0; vertex_i < n; ++vertex_i){
		if(color[vertex_i] == WHITE)
		Dfs(vertex_i, n);
	}
	for (int id = 0; id < n; ++id)
		printf("%d %d %d\n", id+1, discoveredtime[id], finishedtime[id]);
	return 0;
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<queue<int> > a(n+1); 
    //入力
    for(int i = 1; i <= n; i++){
        int id, num;
        cin >> id >> num;
        for(int j = 0; j < num; j++){
            int temp;
            cin >> temp;
            a[i].push(temp);
        }
    }
    vector<int> d(n+1);
    vector<int> f(n+1);
    stack<int> place;
    place.push(1);
    int time = 0;
    while(place.size()){
        int now = place.top();
        //初めて来たらタイムスタンプ
        if(!f[now]){
            f[now] = ++time;
        }
        //次に行く場所を決める
        while(a[now].size()){
            //まずnowの隣接リストから探す
            if(!f[a[now].front()]){
                place.push(a[now].front());
                a[now].pop();
                break;
            }else{
                a[now].pop();
            }
        }
        //nowの隣接リストに見探索の頂点が無ければ一個前に戻る。
        //同時に終了のタイムスタンプを押す
        if(now == place.top()){
            place.pop();
            d[now] = ++time;
        }
        //たどり切ったときに、探索出来ない場所に見探索の頂点があれば次の目的地にする
        if(place.size() == 0){
            for(int i = 1; i <= n; i++){
                if(f[i] == 0){
                    place.push(i);
                    break;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << f[i] << " " << d[i] << endl;
    }
    return 0;
}