Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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;
}