Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

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

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


void dfs_visit(int r){
    
   
    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){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
            }
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;nt[i]=0;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mp[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}

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

struct VRTX {
	int dt, ft, v[101];
};

int curtime = 1;
VRTX ver[101];

void depthFirstSearch(int u);

int main() {
	int i, j, n, u, k;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> ver[u].v[j];
		}
	}
	
	for (i = 1; i <= n; i++) {
		depthFirstSearch(i);
	}

	for (i = 1; i <= n; i++) {
		cout << i << " " << ver[i].dt << " " << ver[i].ft << endl;
	}

	return 0;
}

void depthFirstSearch(int u) {

	if (ver[u].dt == 0) {
		int i = 0;

		ver[u].dt = curtime++;

		while (ver[u].v[i] != 0) {
			depthFirstSearch(ver[u].v[i]);
			i++;
		}

		ver[u].ft = curtime++;

		return;
	}
	return;
}

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

class TVertex
{
    int FIndex;
    std::vector<TVertex*> FList;
    int FDiscoveryTime;
    int FFinishTime;

public:
    TVertex(int Index)
     : FIndex(Index), FDiscoveryTime(0), FFinishTime(0)
    {}
    void AddPath(TVertex* Vertex)
    {
        FList.push_back(Vertex);
    }
    void PrintTime(std::ostream& out)const
    {
        out << FIndex << " " << FDiscoveryTime << " " << FFinishTime << std::endl;
    }
    int DepthFirstSearch(int Time)
    {
        if(FDiscoveryTime) return Time;
        FDiscoveryTime = Time++;
        for(std::vector<TVertex*>::iterator It = FList.begin(); It != FList.end(); ++It){
            TVertex* V = *It;
            Time = V->DepthFirstSearch(Time);
        }
        FFinishTime = Time++;
        return Time;
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n+1);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 1);
        assert(Index <= FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v;
            in >> v;
            FTable[Index]->AddPath(FTable[v]);
        }
    }
    void DepthFirstSearch()
    {
        int Time = 1;
        for(int i = 1; i < FTable.size(); ++i){
            Time = FTable[i]->DepthFirstSearch(Time);
        }
    }
    void PrintTime(std::ostream& out)
    {
        for(int i = 1; i < FTable.size(); ++i){
            FTable[i]->PrintTime(out);
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.DepthFirstSearch();
    Graph.PrintTime(std::cout);
    return 0;
    
}

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

using i64 = int64_t;

using Graph = vector<vector<int>>;

int dfs(int u, int t, vector<pair<int, int>> &ans, const Graph &graph){
    ans[u].first = t;
    for(auto v: graph[u]){
        if(ans[v].first == -1){
            t = dfs(v, t+1, ans, graph);
        }
    }
    ans[u].second = t + 1;
    return t + 1;
}

int main(){
    int n;
    cin >> n;
    Graph graph(n+1, vector<int>());
    for(int i=0;i<n;++i){
        int u, k;
        cin >> u >> k;
        for(int j=0;j<k;++j){
            int v;
            cin >> v;
            graph[u].push_back(v);
        }
    }
    vector<pair<int, int>> ans(n+1, make_pair(-1, -1));
    int t = 0;
    for(int u=1;u<=n;++u){
        if(ans[u].first == -1)
            t = dfs(u, t+1, ans, graph);
    }
    for(int i=1;i<=n;++i){
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}