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 "bits/stdc++.h"

using namespace std;

void dfs(int curr, int& ts, const vector<set<int> >& graph
        , vector<int>& d, vector<int>& f) {

    ++ts;
    d[curr] = ts;
    const set<int>& nextNodes = graph[curr];
    for (int n : nextNodes) {
        if (d[n] > 0) {
            continue;
        }
        dfs(n, ts, graph, d, f);
    }
    ++ts;
    f[curr] = ts;
}

void Main() {
    int n;
    cin >> n;
    vector<set<int> > graph(n, set<int>());
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        --u;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            --v;
            graph[u].insert(v);
        }
    }

    vector<int> d(n, -1);
    vector<int> f(n, -1);
    int timestamp = 0;
    for (int i = 0; i < n; ++i) {
        if (d[i] < 0) {
            dfs(i, timestamp, graph, d, f);
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << (i + 1) << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

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

void dfs_visit(int u, int N, vector<vector<int>> &M, vector<string> &color,
               int &tt, vector<int> &start, vector<int> &finish) {
    color[u] = "GRAY";
    tt++;
    start[u] = tt;
    for (int v = 0; v < N; v++) {
        // if (M[u][v] == 0);
        //     continue;
        // cout << v << endl;
        if (M[u][v] == 1 && color[v] == "WHITE")
        {
            dfs_visit(v, N, M, color, tt, start, finish);
        }
    }
    color[u] = "BLACK"; // 訪問完了
    tt++;
    finish[u] = tt;
}

void dfs(int N, vector<vector<int>> &M, vector<string> &color,
         int &tt, vector<int> &start, vector<int> &finish) {

    tt = 0;
    // cout << "hee" << endl;
    for (int u = 0; u < N; u++)
    { // uが未訪問ならば
        if (color[u] == "WHITE") {
            // cout << u << " " << tt << endl;
            dfs_visit(u, N, M, color, tt, start, finish);
        }
    }
    for (int u = 0; u < N; u++) {
        cout << u + 1 << " " << start[u] << " " << finish[u] << endl;
    }
}

int main() {
    int N;
    cin >> N;

    vector<vector<int>> M(N, vector<int>(N, 0));
    vector<string> color(N, "WHITE");
    int tt = 0;
    vector<int> start(N, 0);
    vector<int> finish(N, 0);

    int u, k, v;
    for (int i = 0; i < N; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs(N, M, color, tt, start, finish);
}

C++: #include<iostream>
#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;

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++){ // 訪問した場所は探索しなくていいため、v+1にしている？
        nt[u] = v+1;
        if(M[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] = GRAY;
    d[r] = ++tt;

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

void dfs(){
    // 初期化
    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(int argc, char const *argv[])
{
    int u, k, v;

    cin >> n;
    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++){
        cin >> u >> k;
        u--; // 0 origin
        for(int j=0; j<k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int t;
int N;
int d[110], f[110];
vector<vector<int> > adj(110);
void dfs(int cur){
    d[cur] = t;
    t += 1;
    //cerr << "visiting " << cur << " " << t << endl;
    for(int i = 0; i < adj[cur].size(); ++i){
        int dst = adj[cur][i];
        if(d[dst] == 0){
            dfs(dst);
        }
    }
    f[cur] = t;
    t++;
}

int main(){
    cin >> N;
    t = 1;
    int u, k;
    for(int i = 0; i < N; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            adj[u].push_back(v);
        }
        sort(adj[u].begin(), adj[u].end());
    }
    dfs(1);
    for(int i = 1; i < N+1; ++i){
        cout << 1 << " " << d[i] << " " << f[i] << endl;
    }
}