Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

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

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

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