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>
#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++){ 
        color[u]=WHITE; 
    }

    tt=0;

    for(u=0; u<n; u++){
        //未訪問の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>
using namespace std;

const int N = 100;
const int white = 0;
const int gray = 1;
const int black = 2;

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

//?????°dfs
void dfs_visit(int u){
    int v;
    color [u] = gray;
    d[u] = ++tt; //??????????¨????
    for (int 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 (int u = 0; u < n; ++u) {
        color[u] = white;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == white) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << f[u] << " " << endl;
    }
}

int main(){
    int u,v,k,i,j;
    M[N][N] = {0};
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        u --;
        for (int j = 0; j < k ; ++j) {
            cin >> v;
            v --;
            M[u][v] = 1;
        }
    }
    
    dfs();
    return 0;

}

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

struct node {
	int num;
	std::vector<int> child;
};

int recurcive(node nodes[],int d[100], int f[100], int n, int count) {
	d[n] = count++;
	for (size_t i = 0; i < nodes[n].child.size(); i++) {
		if (d[nodes[n].child[i]] == 0) {
			count = recurcive(nodes, d, f, nodes[n].child[i], count);
		} else {
			nodes[n].child.erase(std::find(nodes[n].child.begin(), nodes[n].child.end(), nodes[n].child[i]));
		}
	}
	f[n] = count++;

	return count;
}

int main() {
	int node_num;
	node nodes[100];
	std::cin >> node_num;

	for (int i = 0; i < node_num; i++) {
		int n, num;
		std::cin >> n >> num;
		for (int j = 0; j < num; j++) {
			int val;
			std::cin >> val;
			nodes[n - 1].child.push_back(val - 1);
		}
	}

	std::stack<int> st, st2;
	std::vector<int> gone;
	int d[100], f[100];
	int count = 1;

	for (int i = 0; i < 100; i++)
		d[i] = 0;

	recurcive(nodes, d, f, 0, 1);

	for (int i = 0; i < node_num; i++) {
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
	
	return 0;
}

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

using namespace std;

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

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

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    timeT++;
    if(f[node] == 0){
        f[node] = timeT;
    }
    return;
}
    
int main(){
    
    time(NULL);
    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);
        }
    }
    
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == 0){
            dfs(i);
        }
    }

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

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}


int main(){
    int n;
    cin >> n;
    vector<vi> es(n);
    rep(i, n) {
        int x, k;
        cin >> x >> k;
        --x;
        rep(j, k) {
            int y;
            cin >> y;
            --y;
            es[x].pb(y);
        }
    }
    vi in(n);
    vi out(n);
    int cnt = 0;
    vi used(n);
    function<void(int)> dfs = [&] (int cur) {
        if(used[cur]) return;
        used[cur] = true;
        in[cur] = ++cnt;
        for(auto&& to : es[cur]) dfs(to);
        out[cur] = ++cnt;
    };
    rep(i, n) if(used[i] == 0) dfs(i);
    rep(i, n) {
        cout << i+1 << " " << in[i] << " " << out[i] << endl;
    }
    return 0;
}