Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: /*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B    "Depth First Search"?????¨??????
????????????1.5h????§£????????±???????????¢?´¢
?°??????????????????????????????????????????????????§£???????????£????????§???????????¨??????
*/
#include <iostream>
using namespace std;
int a[100][100]={},f[100]={},d[100]={},T[200]={};//a[i][j]???i????§??????¨??????j??????????°????????????????T[i]?????????i???????????????????????????
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>a[u][j];
		}
	}
	T[1]=1;//????????????????????????
	f[1]=1;
	int s=1;//s?????¨????????¨???????????????????????????????????????
	for(int time=2;time<=2*n;time++){
		for(int j=0;j<100;j++){
			if(a[T[time-1]][j]==0){//?????????????????????????????????????????????????????????????????????
				d[T[time-1]]=time;
				if(f[T[time-1]]==s){//???????????¨?????¢?´¢???????????£??????
					for(int i=1;i<n;i++){
						if(f[i]==0){//??°????????¨?????????i
							T[time+1]=i;
							time++;
							f[i]=time;
							break;
						}
					}
					s=time;//s?????´??°
				}else{
					T[time]=T[f[T[time-1]]-1];//T[time]??????????????\?????????????????????????????????
				}
				break;
			}
			else if(f[a[T[time-1]][j]]==0){//?????£????????¨???????????????????????????
				f[a[T[time-1]][j]]=time;
				T[time]=a[T[time-1]][j];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<f[i]<<" "<<d[i]<<endl;
	}
}

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

using namespace std;

int G[100][100];
int In[100];
int Out[100];
void init() {
	for (int i = 0; i < 100; i++) {
		for(int j = 0; j < 100; j++)
			G[i][j] = 0;
		In[i] = -1;
		Out[i] = -1;
	}	
}

void dfs(int src);

int main() {
	init();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v_j;
			cin >> v_j;
			G[u - 1][v_j - 1] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		if (In[i] == -1) dfs(i);		
	}
	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << In[i] << " " << Out[i] << endl;
}

int t = 1;

void dfs(int cur) {
	In[cur] = t;
	t++;
	for (int dst = 0; dst < 100; dst++)
		if (G[cur][dst] == 1 && In[dst] == -1)
			dfs(dst);
	Out[cur] = t;
	t++;
}

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

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

using namespace std;

static const int N =120;

int n;//頂点数
int T;//時刻
int d[MAX];//発見時刻
int f[MAX];//終了時刻
int color[MAX];//判別
int M[N][N];

void dfs_v(int u){
   
    color[u] = GRAY;
    T++;
    d[u] = T;
    for(int v=0; v<n; v++){
        if(M[u][v]==0){
            continue;
        }
        if(color[v]==WHITE){
            dfs_v(v);
        }
    }
    
    color[u]= BLACK;
    T++;
    f[u] = T;
}

void dfs(){
    for(int j=0; j<n; j++){
        color[j] = WHITE;
        
    }
    T = 0;
    
    for(int j=0; j<n; j++){
        if(color[j] == WHITE){
            dfs_v(j);
        }
    }
    
    for(int j=0; j<n; j++){
        printf("%d %d %d\n", j+1, d[j], f[j]);
    }
}

int main(){
    
    
    //cin >> n;
    
    int Adj[MAX];
    int u, k, v;
    
    scanf("%d", &n);
    
    for(int b=0; b<n; b++){
        for(int i=0; i<n; i++){
        M[b][i] = 0;
        }
    }
    
    
    
    for(int j=0; j<n; j++){
        //cin >> u >>k;
        scanf("%d %d", &u, &k);
        u--;
        for(int a=0; a<k; a++){
            /*cin >> v;
            Adj[v] = 1;
            
            if(Adj[v] != 0){
            M[u][v] = 1;
            }*/
            
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    return 0;
}