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 <cstdio>
#include <iostream>
#include <stack>
#define MAX_VERTEXES 100
#define ZERO 0
#define NIL -1

using namespace std;

//think easy make easy

int n;//num of vertexes(頂点)
int matrix_graph[MAX_VERTEXES+1+1][MAX_VERTEXES+1+1];//1オリジン

stack<int> stk;
bool discovered[MAX_VERTEXES+1+1];//1オリジン
int discovered_time[MAX_VERTEXES+1+1];
int completed_time[MAX_VERTEXES+1+1];
int current_time = 0;

void DFS(int v){
	int v_tmp;
	for(int i=1;i<=n;i++){
		//if(i == v);
		if(matrix_graph[v][i] == 1 && !discovered[i]){
			current_time++;
			discovered_time[i] = current_time;
			stk.push(v);
			matrix_graph[v][i] == 0;
			discovered[i] = true;
			DFS(i);
		}else if(matrix_graph[v][i] == 1 && discovered[i]){
			matrix_graph[v][i] == 0;
		}

		if(i == n){
			current_time++;
			completed_time[v] = current_time;
			//if(!stk.empty())
			//{
				//cout <<stk.top() <<endl;
				//v_tmp = stk.top();
				//stk.pop();
				//DFS(v_tmp);
			//}
		}
	}
}

int main(){
	scanf("%d",&n);

	int v_num;
	int k;//v_numの出次数

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			matrix_graph[i][j] = ZERO;
		}
	}

	for(int i=0;i<n;i++){
		scanf("%d",&v_num);
		scanf("%d",&k);

		for(int j=0;j<k;j++){
			int v_num2;
			scanf("%d",&v_num2);
			matrix_graph[v_num][v_num2] = 1;
		}
	}

	for(int i=1;i<=n;i++){
		discovered[i] = false;
		discovered_time[i] = NIL;
		completed_time[i] = NIL;
	}

	for(int i=1;i<=n;i++){
		current_time++;
		if(!discovered[i]){
			discovered[i] = true;
			discovered_time[i] = current_time;
			DFS(i);
		}
	}

	for(int i=1;i<=n;i++){
		cout <<i <<" " <<discovered_time[i] <<" " <<completed_time[i] <<endl;
	}

	return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[100]={0}, p=0;

void dfs(int n){
    if(visit[n]!=1){
        visit[n] = 1;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]==1) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]=1;
        }
    }
    for(int i=1; i<num+1; i++){
        if(visit[i]!=1) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

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() {
    int u;
    for ( u = 0; u < n; u++) {
        if ( color[u] == WHITE ) dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}

int main() {
    int u, v, k, i, j;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) M[i][j] = 0;
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for ( j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

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

struct VRTX {
	int dt, ft, v[101];
};

int curtime = 1;
VRTX ver[101];

void depthFirstSearch(int u);

int main() {
	int i, j, n, u, k;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> ver[u].v[j];
		}
	}

	depthFirstSearch(1);

	for (i = 1; i <= n; i++) {
		cout << i << " " << ver[i].dt << " " << ver[i].ft << endl;
	}

	return 0;
}

void depthFirstSearch(int u) {
	int i = 0;

	if (ver[u].dt == 0) {
		ver[u].dt = curtime++;

		while (ver[u].v[i] != 0) {
			depthFirstSearch(ver[u].v[i]);
			i++;
		}

		ver[u].ft = curtime++;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
vector<int> d, f;
 
void dfs(int node){
    time++;

    if(d[node] == 0){
        d[node] = time;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    time++;
    if(f[node] == 0){
        f[node] = time;
    }
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    dfs(1);

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

int n, u, k, v, t;
int adjList[101][101];
int adjNum[101];
bool visited[101];

int d[101], f[101];

void dfs(int u) {
    if (visited[u]) return;
    visited[u] = true;

    d[u] = t;
    t++;

    for (int i = 0; i < adjNum[u]; ++i) {
        dfs(adjList[u][i]);
    }

    f[u] = t;
    t++;

}

int main () {
	scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        adjNum[u-1] = k;
        for (int j = 0; j < k; ++j) {
            scanf("%d", &v);
            adjList[u-1][j] = v-1; // all IDs start from 1
        }
    }

    t = 1;
    for (int u = 0; u < n; ++u) {
        dfs(u);
        cout << u+1 << " " << d[u] << " " << f[u] << "\n";
    }

	return 0;
}