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++: #include <iostream>
#include <vector>
using namespace std;
vector<int> E[101];
bool visited[101];
int in[101];
int out[101];
int count=0;
int nv(int n)
{
	int i=1;
	for(i=1;i<=n;i++)
	{
		if ( visited[i]==false )
			return i;
	}
	if (i>n) return 0;
}

void bfs(int n)
{
	visited[n]=true;
	in[n]=++count;
	for(vector<int>::iterator it=E[n].begin();it!=E[n].end();++it)
	{
		int now=*it;
		if(visited[now]==false)
			bfs(now);
	}
	out[n]=++count;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int e,n0;
		cin>>e>>n0;
		for(int j=0;j<n0;j++)
		{
			int t;
			cin>>t;
			E[e].push_back(t);
		}
		visited[i]=false;
		in[i]=out[i]=0;
	}

	int now=nv(n);
	while(now!=0)
	{
		bfs(now);
		now=nv(n);
	}


/*	for(int i=1;i<=n;i++)
	{
		for(vector<int>::iterator it=E[i].begin();it!=E[i].end();++it)
			cout<<*it<<" ";
		cout<<endl;
	}
*/
	for(int i=1;i<=n;i++)
		cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return 0;

	

}

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

int n, t;
int v[100][100];
int d[100], f[100], r[100];

void stamp(int id) {
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = 0; i < n; i++)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i > n - 1 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			int j1, ct = 0;
			for (int j = n - 1; j > -1; j--)
				if (v[j][id - 1] == 1 && f[j] == 0 && d[j] != 0) {
					j1 = j;
					ct++;
				}
			if (ct == 1)
				stamp(j1 + 1);
			else {
				for (int j = 1; j < n; j++)
					if (d[j] == d[id - 1] - 1)
						stamp(j + 1);
			}

			int k = 0;
			while (d[k] != 0)
				k++;
			if (k < n)
				stamp(k + 1);
		}
	}
	else	
		return;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		d[i] = 0;
		f[i] = 0;
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u - 1][s - 1] = 1;
		}
	}

	t = 1;
	stamp(1);

	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAX=200;

int state[MAX],d[MAX],f[MAX],N;
vector<int> T[MAX];
stack<int> S;

void DFS(){
    int time=0,count=0;
    while(count!=N){
        for(int j=0;j<N;j++){
            if(state[j]==0){
                S.push(j);
                state[j]=1;
                time++;
                d[j]=time;
                break;
            }
        }
    while(S.size()){
        int a=S.top();
        bool flag=true;
        for(int i=0;i<T[a].size();i++){
            if(state[T[a][i]]==0){
                S.push(T[a][i]);
                state[T[a][i]]=1;
                time++;
                d[T[a][i]]=time;
                flag=false;
                break;
            }
        }
            if(flag){
                time++;
                state[a]=2;
                count++;
                f[a]=time;
                S.pop();
            }
            
        }
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
   
    int u,k,a;cin>>N;
    
    for(int i=0;i<N;i++){
        state[i]=0;
        d[i]=0;
        f[i]=0;
    }
    
    for(int i=0;i<N;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>a;
            a--;
            T[u].push_back(a);
        }
    }
    DFS();
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<stack>
#define MAX 105
#define WT 0
#define GR 1
#define BK 2

using namespace std;

int M[MAX][MAX];
int cr[MAX], d[MAX], f[MAX];
int t;
stack<int> ck;
void dfs_init(int n)
{
    t = 1;

    for(int i = 1; i <= n; i++)
        cr[i] = WT;

    return;
}
void dfs(int k,int n)
{
    if(cr[k] == WT)
    {
        cr[k] = GR;
        d[k] = t;
        t++;
        ck.push(k);

        for(int i = 1; i <= n; i++)
        {
            if(M[k][i] == 1 && cr[i] == WT)
                dfs(i,n);
            else if(i == n)
            {
                dfs(ck.top(),n);ck.pop();
            }
        }
    }
    else if(cr[k] == GR)
    {
        ck.pop();
        cr[k] = BK;
        f[k] = t;
        t++;

        if(!ck.empty())
            dfs(ck.top(),n);
        else
            return;
    }
}
int main()
{
    int i, j, n, p, q, tmp;

//Set the matrix: M[n][n]
    for(i = 0; i < MAX; i++)
        for(j = 0; j < MAX; j++)
            M[i][j] = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
    {
        scanf("%d%d", &p, &q);

        for(j = 0; j < q; j++)
        {
            scanf("%d", &tmp);
            M[p][tmp] = 1;
        }
    }

    //DFS:d[v] and f[v] for start and end
    dfs_init(n);
    dfs(1,n);

    for(i = 1; i <= n; i++)
        printf("%d %d %d\n", i, d[i], f[i]);

    return 0;
}