Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

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

using namespace std;

static const int N = 100; // 1 <= n <= 100
static const int WHITE = 0; // 未訪問は0
static const int GRAY = 1; // 訪問中は1
static const int BLACK = 2; // 訪問完了は2

int n; // 頂点数n
vector<vector<int>> M(N, vector<int>(N,0)); // M[u][v]：uからvに出ているか否か
vector<int> color(N), d(N), f(N); // d(i)：頂点i発見時刻，f(i)：頂点i完了時刻
int tt; // 経過時間tt
vector<int> nt(N); //

// uに隣接するvを番号順に取得
int next(int u) {
    for ( int v = nt[u]; v < n; v++ ) {
        nt[u] = v + 1;
        if (M[u][v]) {
            return v;
        }
    }
    return -1;
}

// 地点rについてスタックを用いた深さ優先探索
void dfs_visit(int r) {
    //初期化
    for ( int i = 0; i < n; i++ ){
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    
    tt++;
    d[r] = tt;
    
    while ( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if ( v != -1 ) {
            if ( color[v] == WHITE ) {
                color[v] = GRAY;
                tt++;
                d[r] = tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            tt++;
            f[u] = tt;
        }
    }
}

void dfs() {
    // 初期化
    for ( int i = 0; i < n; i++ ) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    
    // 未訪問のuを始点として深さ優先探索
    for ( int u = 0; u < n; u++ ){
        if ( color[u] == WHITE ){
            dfs_visit(u);
        }
    }
    
    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(){
    int u,k,v;
    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<algorithm>

using namespace std;

int cnt = 0;
int discoverd[100] = { 0 };
int finished[100] = { 0 };
int n = 0;

void dfs(int index, int** mat);

int main() {
	int row,size,tmp;
	cin >> n;
	int** mat = new int* [n];
	for (int i = 0;i < n;i++) {
		cin >> row >> size;
		mat[row - 1] = new int[n];
		for (int j = 0;j < n;j++) {
			mat[row - 1][j] = 0;
		}
		for (int j = 0;j < size;j++) {
			cin >> tmp;
			mat[row - 1][tmp - 1] = 1;
		}
	}
	for (int i = 0;i < n;i++) {
		if (discoverd[i] == 0)dfs(i, mat);
	}
	for (int i = 0;i < n;i++) {
		cout << i + 1 << " " << discoverd[i] << " " << finished[i] << endl;
	}
	
}

void dfs(int index, int** mat) {
	cnt++;
	discoverd[index] = cnt;
	for (int i = 0;i < n;i++) {
		if (mat[index][i] == 1 && discoverd[i] == 0) {
			dfs(i, mat);
		}
	}
	cnt++;
	finished[index] = cnt;
}

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

const int maxn = 100 + 5;
int a[maxn][maxn];
bool vis[maxn];
int d[maxn];
int f[maxn];
int time = 0;
int n;

void dfs(int u)
{
    vis[u] = true;
    d[u] = ++time;
    for (int i = 1; i <= n; i++)
        if (a[u][i] && !vis[i])
            dfs(i);
    f[u] = ++time;
}

int main()
{
    while (scanf("%d", &n) != EOF)
    {
        time = 0;
        memset(a, 0, sizeof(a));
        memset(vis, false, sizeof(vis));

        int u, k, x;
        for (int i = 0; i < n; i++)
        {
            scanf("%d %d", &u, &k);
            for (int j = 0; j < k; j++)
            {
                scanf("%d", &x);
                a[u][x] = 1;
            }
        }

        dfs(1);
        for (int i = 1; i <= n; i++)
            printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 110;
vector<int> G[MAX];
int dtime[MAX];
int ftime[MAX];
int n;
int tim;

void dfs(int p) {
    if (ftime[p] == -1) dtime[p] = ++tim;
    else return;
    for (int i = 0; i < G[p].size(); i++) {
        dfs(G[p][i]);
    }
    if (ftime[p] == -1) ftime[p] = ++tim;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {G[i].clear(); dtime[i]=-1; ftime[i]=-1;}
    tim = 0;
    for (int i = 1; i <= n; i++) {
        int p, k;
        scanf("%d %d", &p, &k);
        while (k--) {
            int ne = 0;
            scanf("%d", &ne);
            G[p].push_back(ne);
        }
        sort(G[p].begin(), G[p].end());
    }
    for (int i = 1; i <= n; i++) {
        dfs(i);
    }
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, dtime[i], ftime[i]);
    }
    return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int mat[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]+=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(mat[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	}
	t += 1; 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<100;i++){
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			mat[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			mat[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;i++){
    if(c[i]!=1){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++)
    {
      cout<<(i+1)<<' '<<mytime1[i]<<' '<<mytime2[i]<<endl;
    }
}