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 <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1

// グラフの隣接頂点リスト表現
struct GraphAV{
    int p;  // 頂点数
    int q;  // 辺数
    // int AV[VMAX][DMAX]; 
    vector<vector<int>> AV;  // 隣接頂点リスト
};

GraphAV G;
// int d[VMAX],f[VMAX];
// bool seen[VMAX];
vector<int> d(VMAX);
vector<int> f(VMAX);
vector<bool> seen(VMAX);
int t=1;
void DFS(int v,int& t);

int main(){
    cin>>G.p;

    d.resize(G.p+1);
    f.resize(G.p+1);
    G.AV.resize(G.p+1);
    seen.resize(G.p+1);
    G.AV[0]={NOTUSED};
    d[0]=NOTUSED;
    
    for(int i=1; i<=G.p; i++){
        int u,k;
        cin>>u>>k;
        G.AV[u].resize(k);
        for(int j=0; j<k; j++){
            cin>>G.AV[u][j];
        }
    }

    for(int i=1; i<=G.p; i++){
        if(seen[i]){
            continue;
        }
        DFS(i,t);
    }

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

void DFS(int v,int& t){
    d[v]=t++;

    seen[v]=true;
    // v から行ける各頂点 adj_v について
    for(int adj_v:G.AV[v]){
        if(seen[adj_v]) continue; // adj_v が探索済なら何もしない
        DFS(adj_v,t);  // 再帰的に探索
    }

    f[v]=t++;
}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int>> G[101];

int ti = 1;

void dfs(int id) {
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0, l=adj.size(); i<l; ++i) {
		if ( ! d[adj[i]]) {
			dfs(adj[i]);
		}
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	dfs(1);

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

C++: #include <cstdio>
#include <vector>
using namespace std;
int Begin;
int step=1;
int root[105]={0};
typedef struct{
	int id;
	vector<int>next;
	int num;
	int find;
	int finish;
}inf;
void input(int cases,inf table[]){
	for(int i=0;i<cases;i++){
		int id;
		scanf("%d",&id);
		table[id].id=id;
		scanf("%d",&table[id].num);
		for(int i=0;i<table[id].num;i++){
			int next;
			scanf("%d",&next);
			table[id].next.push_back(next);
			root[next]=1;
		}
		table[id].find=-1;
		table[id].finish=-1;
	}
}
void dfs(inf table[],int now){
	if(table[now].num==0){
		table[now].find=step;
		step++;
		table[now].finish=step;
		step++;
		return;
	}else{
		if(table[now].find==-1){
			table[now].find=step;
		}
		step++;
		for(int i=0;i<table[now].num;i++){
			if(table[table[now].next[i]].find==-1){
				dfs(table,table[now].next[i]);				
			}
		}
		table[now].finish=step;
		step++;
	}
}
void find_begin(int cases){
	for(int i=1;i<=cases;i++){
		if(root[i]==0){
			Begin=i;
			break;
		}
	}
}
int main(){
	int cases;
	scanf("%d",&cases);
	inf table[105];
	input(cases,table);
	find_begin(cases);
	dfs(table,Begin);
	for(int i=1;i<=cases;i++){
		printf("%d %d %d\n",i,table[i].find,table[i].finish);
	}
}

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

void DFS(vector<vector<int> >& G,
        vector<pair<int, int> >& rec, int i) {
    if (rec[i].first != -1) return;
    static int t = 1;
    rec[i].first = t++;
    for (int j = 1; j <= G[i].size(); j++) {
        if (G[i][j]) DFS(G, rec, j);
    }
    rec[i].second = t++;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; i++) {
        int num, k;
        cin >> num >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[i][v] = 1;
        }
    }
    vector<pair<int, int> > record(n + 1, make_pair(-1, -1));
    int t = 1;
    for (int i = 1; i <= n; i++) {
        DFS(G, record, i);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << record[i].first
                  << " " << record[i].second << endl;
    }

    return 0;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];
int counter = 0;
int D[MAX];
int F[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(int cur){
    counter++;
    D[cur] = counter;
    for(int i=0; i< num;i++){
        if(matrix[cur][i] == 1 && D[i]== 0)
            dfs(i);
    }
    F[cur] = counter+1;
    counter++;
    return;
}

int main(){
    input();
    for(int i=0;i<MAX;i++){
        D[i] = 0;
        F[i] = 0;
    }
    dfs(0);
    for(int i=0;i<num;i++){
        cout << i+1 << " " << D[i] << " " << F[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

int d[110];
int f[110];
vector<int> edge[110];
int t=0;
void dfs(int now){
    sort(All(edge[now]));
    if(edge[now].size()==0){
        t++;
        f[now]=t;
    }else{
        for(int i=0;i<edge[now].size();i++){       
            if(d[edge[now][i]]==-1){
                t++;
                d[edge[now][i]]=t;
                dfs(edge[now][i]);
            }
            if(i==edge[now].size()-1){
                t++;
                f[now]=t;
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fill(d,d+110,-1);
    fill(f,f+110,-1);
    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 x;
            cin>>x;
            edge[u].push_back(x);
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==-1){
            t++;
            d[i]=t;
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl; 
    }

}