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 <stdio.h>
#define WHITE 0
#define GRAY  1
#define BLACK 2
int color[100];
int d[100],f[100];
int G[100][100];
int n, time = 0;
void dfs(int u)
{
    color[u] = 1;
    d[u] = ++time;
    for (int i = 0; i < n; i++)
    {
        if (G[u][i]==1 && color[i] == 0)
        {
            dfs(i);
        }
    } 
    color[u] = 2;
    f[u] = ++time;
    return;
}
int main()
{
    int k,u,v;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            G[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);
            G[u-1][v-1] = 1;
        } 
    } 
    for (int i = 0; i < n; i++)
    {
        color[i] = 0; 
        d[i] = 0;
        f[i] = 0;
    } 
    for (int i = 0; i < n; i++)
    {
        if(color[i]==0) dfs(i); 
    } 
    for (int i = 0; i < n; i++)
    {
        printf("%d %d %d\n", i+1, d[i], f[i]); 
    } 
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, t;
vector<int> G[110];
vector<int> d(110), f(110), visited(110, -1); 

void dfs_visit(int u) {
    visited[u] = 0;
    d[u] = ++t;
    for (int v = 0; v < G[u].size(); v++) {
        if (visited[G[u][v]] == -1) {
            dfs_visit(G[u][v]);
        }
    }
    visited[u] = 1;
    f[u] = ++t;
}

void dfs() {
    for (int u = 0; u < n; u++) visited[u] = -1;
    t = 0;
    for (int u = 0; u < n; u++) {
        if (visited[u] == -1) dfs_visit(u);
    }
    for (int u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    cin >> 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;
            G[u-1].push_back(v-1);
        }
    }
    dfs();
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

//再帰関数による深さ優先探索
void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt; //最初の訪問
    for(v=0; v<n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt; //訪問の終了
}

void dfs(){
    int u;
    //初期化
    for(u=0; u<n; u++) color[u] = WHITE;
    tt = 0;

    for(u=0; u<n; u++){
        //未訪問のuを始点として深さ優先探索
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u=0; u<n; u++){
        printf("%d %d %d\n", u+1, d[u], f[u]); //タイムスタンプの出力
    }
}

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<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int timex = 0;

int n;

string *color = new string[n];

int *d = new int[n];

int *f = new int[n];

int c[100][100];

void dfs(int u){
  color[u] = "glay";
  d[u] = ++timex;


  for(int v = 0; v < n; v++){
    if(c[u][v] == 1 && color[v] == "white"){
      dfs(v);
    }
  }

color[u] = "black";
f[u] = ++timex;



}

int main(){

  cin >> n;

  color = new string[n];

  d = new int[n];

  f = new int[n];


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

  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      c[i][v - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    color[i] = "white";
  }

  for(int i = 0; i < n; i++){
    if(color[i] == "white"){
      dfs(i);
    }
  }



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




  return 0;
}

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

#define MAX 100

stack<int> G;
int Graph[MAX+1][MAX+1];
int result[MAX+1][2];
int n;
int cnt = 0;

void dfs(int idx) {
    bool bl = false;
    for(int i=1; i<=n; i++) {
        //もし一つでも残っているノードがあればpushする
        if(Graph[idx][i]==1) {
            Graph[idx][i] = 0;
            //cout << "push: " << i << endl;
            cnt++;
            result[i][0] = cnt;
            G.push(i);
            dfs(i);
            bl = true;
        }
    }
    //一つも残っていなかったらpopする
    if(bl==false) {
        //cout << "pop: " << G.top() << endl;
        cnt++;
        result[G.top()][1] = cnt;
        G.pop();
        if(G.empty()) {
            return;
        }
        else {
            dfs(G.top());
        }
    }
}

int main() {
    int idx, g_num, a;

    cin >>n;
    for(int i=0; i<n; i++) {
        cin >> idx >> g_num;
        for(int j=0; j<n; j++) {
            Graph[idx][j] = 0;
        }
        for(int j=0; j<g_num; j++) {
            cin >> a;
            Graph[idx][a] = 1;
        }
    }
    G.push(1);
    cnt++;
    result[1][0] = cnt;
    cout << "push: " << 1 << endl;
    dfs(1);

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

    return 0;
}