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;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
//Graph I - Depth First Search
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B

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

//WHITE -> ????¨?????????????
//GRAY  -> ?¨????????????????(?¨?????????????????¨???????????????????????????????????????§???????????????)
//BLACK -> ?¨??????????????????????(????¨???????????????????????????????????????????)

int n, M[N][N];
int color[N];//?????????????¨??????¶???
int d[N];//????????????
int f[N];//????????????
int tt;//time stamp

//?????°???????????±???????????¢?´¢
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()
{
	//??¨???????????????color???WHITE????¨????
	for( int u = 0; u < n; u++ ) color[u] = WHITE;
	tt = 0;
	for( int u = 0; u < n; u++ ){
		//????¨??????? u ?????°??????????§?????????¨????????±???????????¢?´¢
		if( color[u] == WHITE ) dfs_visit( u );
	}
	for( int u = 0; u < n; u++ ){
		cout << u + 1 << " " << d[u] << " " << f[u] << endl;
	}
}
int main()
{
	int u;//???????????????
	int k;//??????u?????£??\?????????????????????
	int v;//??????u????¬???°

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

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>

using namespace std;
int n;
list<int> adj[101];
int d[101] = {};
int f[101] = {};

void DFS(int v)
{
    static int num = 1;
    d[v] = num++;
    while (!adj[v].empty())
    {
        if (d[adj[v].front()] == 0)
            DFS(adj[v].front());
        adj[v].pop_front();
    }
    f[v] = num++;
}

void print()
{
    for (int i = 1; i <= n; i++)
    {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main()
{
    int u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u].push_back(v);
            k--;
        }
    }

    DFS(1);

    print();

    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
int n,graph[101][101],visit[101];
int d[101],f[101],t;
const int WHITE=0;
const int GRAY=1;
void dfs(int u){
    visit[u]=GRAY;
    d[u]=++t;
    FOR(v,1,n+1){
        if(graph[u][v]==0) continue;
        if(visit[v]==WHITE) dfs(v);
    }
    f[u]=++t;
    //printf("%d %d %d\n",u,d[u],f[u]);
}
int main(){
    int u,k,v;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d%d",&u,&k);
        REP(j,k){
            scanf("%d",&v);
            graph[u][v]=1;
        }
    }
    FOR(i,1,n+1){
        if(visit[i]==WHITE) dfs(i);
    }
    FOR(i,1,n+1){
        printf("%d",i);
        printf(" %d %d\n",d[i],f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
mat g;
vll d;
vll f;
vbl vis;

lli u,k,v;

lli dfs(lli x,lli t){
    d[x] = t;
    vis[x] = true;
    for(lli i = 0;i < g[x].size();i++){
        if(!vis[g[x][i]]) t = dfs(g[x][i],t+1);
    }
    return f[x] = t + 1;
}

int main(){
    cin >> n;
    g = mat(n+1);
    d = vll(n+1);
    f = vll(n+1);
    vis = vbl(n+1);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v;
            g[u].push_back(v);
        }
    }
    dfs(1,1);
    for(lli i = 1;i <= n;i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}