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<bits/stdc++.h>
using namespace std;
static const int N=100;
enum COLOR{WHITE,GRAY,BLACK};

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

int next(int u)
{
    for(int v=nt[u];v<n;v++)
    {
        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;

    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 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 <stdio.h>

#define VerticesNum 100
typedef unsigned int uint;

struct output
{
    uint uDiscoverTime;
    uint uFinTime;
}Output;

struct output gstOutput[VerticesNum];
uint uTotalTime = 1;

void DepthFirstSearch(uint pGraph[][VerticesNum], uint uSize, uint uRoot)
{
    if(gstOutput[uRoot].uDiscoverTime == 0)
    {
        gstOutput[uRoot].uDiscoverTime = uTotalTime++;
    }
    else
    {
        return;
    }
    
    for(uint i = 0; i < uSize; i++)
    {
        if((pGraph[uRoot][i] == 1) && (gstOutput[i].uDiscoverTime == 0 ))
        {
            DepthFirstSearch(pGraph, uSize, i);
        }
    }
    gstOutput[uRoot].uFinTime = uTotalTime++;
    
    return;
}

int main(void){
    uint arGraph[VerticesNum][VerticesNum] = {};
    
    uint uVertices;
    scanf("%u", &uVertices);
    
    for(uint i = 0; i < uVertices; i++)
    {
        uint uVertexIdx;
        uint OutDegree;
        scanf("%u", &uVertexIdx);
        scanf("%u", &OutDegree);
        for(uint j = 0; j < OutDegree; j++)
        {
            uint AdjacentVertex;
            scanf("%u", &AdjacentVertex);
            arGraph[uVertexIdx - 1][AdjacentVertex - 1] = 1; 
        }
    }
    /*
    for(uint i = 0; i < uVertices; i++)
    {
        for(uint j = 0; j < uVertices; j++)
        {
            printf("%u", stGraph[i][j]);
            (j < (uVertices - 1))
                ? printf(" ")
                : printf("\n");
        }
    }
    */
    for(uint uRoot = 0; uRoot < uVertices; uRoot++)
    {
        DepthFirstSearch(arGraph, uVertices, uRoot);
    }
    
    for(uint i = 0; i < uVertices; i++)
    {
        printf("%d %d %d\n", i + 1, gstOutput[i].uDiscoverTime, gstOutput[i].uFinTime);
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N;
vector<vector<int>> G(110, vector<int>());
vector<int> d(110), f(110), k(110);
vector<bool> visited(110, false);
int t = 0;

void dfs(int v) {
	visited[v] = true;
	d[v] = t;
	//cout << v << " d[" << v << "]:" << d[v] << " " << t << endl;
	rep(i, k[v]) {
		if(visited[G[v][i]]) continue;
		t++;
		//cout << G[v][i] << " " << t << endl;
		dfs(G[v][i]);
		//cout << G[v][i] << " " << t << endl;
	}
	t++;
	f[v] = t;
	//cout << v << " f[" << v << "]:" << f[v] << endl;
	return;
}

int main() {
	cin >> N;
	rep(i,N) {
		int u;
		cin >> u >> k[i];
		G[i] = vector<int>(k[i]);
		rep(j,k[i]) {
			cin >> G[i][j];
			G[i][j]--;
		}
	}
	rep(i,N) {
		if(visited[i] == false) t++,dfs(i);
	}
	rep(i,N) cout << i+1 << " " << d[i] << " " << f[i] << endl;


  return 0;
}

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

int G[105][105]={};
int d[105]={},f[105]={};
int N,T=0;

void Gprint(int n){
    cout<<"\\|";
    for(int i=0; i<n; i++)cout<<i+1;
    cout<<endl;
    for(int i=0; i<n+2; i++)cout<<"-";
    cout<<endl;
    for(int i=0; i<n; i++){
        cout<<i+1<<"|";
        for(int j=0; j<n; j++){
            cout<<G[i][j];
        }
        cout<<endl;
    }
}

void dfs(int n){
    if(d[n])return;
    d[n]=++T;
    for(int i=0; i<N; i++){
        if(G[n][i])dfs(i);
    }
    f[n]=++T;
}

int main(){
    int u,k,v;

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

   Gprint(N);

    for(int i=0; i<N; i++)
        dfs(i);

    for(int i=0; i<N; i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

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

using namespace std;

//4
//1 1 2
//2 1 4
//3 0
//4 1 3

//1 1 8
//2 2 7
//3 4 5
//4 3 6

const int MAX = 100;

int n;

int t = 0;

int G[MAX + 1][MAX + 1];
int d[MAX + 1];
int f[MAX + 1];

int color[MAX + 1];
int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

void dfs(int v) {
	color[v] = GRAY;
	d[v] = ++t;

	for (int i = 1; i <= n; ++i) {
		if (G[v][i] == 1 && color[i] == WHITE)
			dfs(i);
	}

	color[v] = BLACK;
	f[v] = ++t;
}

int main() {

	scanf("%d", &n);

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j)
			G[i][j] = 0;
	}

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

	dfs(1);

	for (int i = 1; i <= n; ++i) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;

}