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<algorithm>
#include<cstdio>
#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++) {
		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(void) {
	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 <bits/stdc++.h>

using namespace std;

//ALDS1_11_B 深さ優先探索の問題
//再帰で解く

void dfs(vector<vector<int>> &G, int s, int &counter,vector<vector<int>> &res,vector<bool> &seen) {
	if (G[s].size() == 0) {
		counter++;
		res[s][1] = counter;
		counter++;
		res[s][2] = counter;
		return;
	}

	counter++;
	res[s][1] = counter;

	for (int i = 0; i < G[s].size(); i++) {
		if (seen[G[s][i]] == true) {
			continue;
		}
		seen[G[s][i]] = true;
		dfs(G, G[s][i],counter,res,seen);

	}
	counter++;
	res[s][2] = counter;
}

int main() {

	int n;
	cin >> n;
	vector < vector<int>> G(n + 1);

	//グラフ隣接リスト読み込み
	int a, b, c;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b;
		for (int j = 0; j < b; j++) {
			cin >> c;
			G[a].push_back(c);
		}
	}

	vector<vector<int>> res(n+1,vector<int> (3));
	for (int i = 1; i <= n; i++) {
		res[i][0] = i;
	}
	
	int aa = 0;
	vector<bool> seen(n + 1,false);
	for (int i = 1; i<= n; i++) {
		if (seen[i]) { continue; }
		seen[i] = true;
		dfs(G, i, aa, res, seen);
	}

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

	return 0;

}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[101][101];
int color[101];
int n;
int d[101], f[101], t;

void search_loop(int i)
{
	int next;
	d[i] = ++t;
	color[i] = GRAY;

	for(next = 1; next <= n; next++){
		if(i == next && G[i][i] > 0) break;
		if(G[i][next] > 0 && color[next] == WHITE){
			search_loop(next);
		}
	}
	f[i] = ++t;
	color[i] = BLACK;

	return;
}

void dfs()
{
	int i;
	for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.

	t = 0;
	for(i = 1; i <= n; i++){
		if(color[i] == WHITE) search_loop(i);
	}
	for(i = 1; i <= n; i++){
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return ;
}

int main()
{
	int i, j, k, e;
	cin >> n;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	do{
		cin >> i >> e;
		for(j = 1; j <= e; j++){
			cin >> k;
			G[i][k] = 1;
		}
	}while(i < n);

	dfs();

	cin >> n;

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAXN = 1000;
int n;
int d[MAXN];
int f[MAXN];
int t;
void solve(int current,vector<vector<int> > &g){
  if(d[current] > 0)return;
  t++;
  d[current] = t;
  
  for(int next:g[current]){
    solve(next,g);
  }
  t++;
  
  f[current] = t;
}

int main(){
  cin >> n;
  vector<vector<int> > g(n+1);
  for(int i = 1;i <= n;i++){
    int u,k;
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      int v;
      cin >> v;
      g[i].push_back(v);
    }
  }
  for(int i = 1;i <= n;i++){
    solve(i,g);
  }
  for(int i = 1;i <= n;i++){
    cout << i << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
vector<int> data[100];
pair<int, int> finds[100];

int dfs(int foo, int timer)
{
    //foo is node number
    if(finds[foo].first!=-1) return timer; 
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i,data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second= ++result;
    return result;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        cin >> temp;
        rep(j, temp)
        {
            int foo;
            cin >> foo;
            data[i].push_back(foo - 1);
        }
    }
    rep(i,100){
        finds[i].first=-1;
    }
    finds[0].second = dfs(0, 0);
    rep(i, n)
    {
        cout << i + 1 << " " << finds[i].first << " " << finds[i].second << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int k[101]={0},v[101][101]={0};
int d[101]={0},f[101]={0};
int cur=0;
void dfs(int id)
{
	if(d[id]!=0)
	{
		return;
	}
	cur++;
	if(d[id]==0)
	{
		d[id]=cur;
	}
	for(int i=0;i<k[id];i++)
	{
		dfs(v[id][i]);
	}
	cur++;
	f[id]=cur;
	return;
}
int main(void)
{
	int n=0,u=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&u);
		scanf("%d",&k[u]);
		for(int j=0;j<k[u];j++)
		{
			scanf("%d",&v[u][j]);
		}
	}
	for(int i=1;i<n;i++)
	{
		if(d[i]==0)
		{
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}