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;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
int n,tim=0;
vector<vector<int> >  lis(100000+5);
vint d(100000+5); vint f(100000+5); vector<bool> flag(100000+5);
void dfs(int now){
    if(flag[now]){
        return;
    }
    flag[now]=true;
    d[now]=++tim;
    rep(i,lis[now].size()){
        dfs(lis[now][i]);
    }
    f[now]=++tim;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    int u,k,v;
    rep(i,n){
        cin>>u>>k;
        rep(j,k){
            cin>>v;
            lis[u].push_back(v);
        }
    }
    REP(i,1,n+1){
        if(!flag[i]){
            dfs(i);
        }
    }    
    REP(i,1,n+1){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return(0);
}

C++: #include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[101][101],start[101],end[101],n,p=0;
void dfs(int u){
	start[u]=++p;
	r(i,1,n+1)if(a[u][i])dfs(i);
	end[u]=++p;
}
int main(){
	int q,qq,qqq;
	cin>>n;
	r(i,0,n){cin>>q>>qq;
		r(i,0,qq){cin>>qqq;
			a[q][qqq]++;
		}
	}
	dfs(1);
	r(i,1,n+1)cout<<i<<' '<<start[i]<<' '<<end[i]<<endl;
}

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

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(vector<vector<int>> &G, int v, int& ptr) {
    first_order[v] = ptr++;

    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, ptr);
    }

    last_order[v] = ptr++;
}

int main(){
    int n;
    cin >> n;
    int u;
    int k;
    vector<vector<int>> G(n);
    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            int a; cin >> a;
            a--;
            G[u].push_back(a);
        }
    }
    
    seen.assign(n, false);
    first_order.resize(n);
    last_order.resize(n);
    int ptr = 1;
    for(int i = 0; i < n; i ++){
        if(!seen[i]) dfs(G, i, ptr);
    }

    for (int v = 0; v < n; v++)
        cout << v + 1 << " " << first_order[v] << " " << last_order[v] << endl;
}

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

vector<vector<int>> G;
vector<int> used;
vector<int> found;
vector<int> done;

int dfs(int v, int t){
    if(used[v]){
        return done[v];
    }
    else{
        used[v] = 1;
        found[v] = t;
    }
    for(long long i=0; i<G[v].size(); i++){
        int nv = G[v][i];
        if(used[nv]) continue;
        else{
            t = dfs(nv, ++t);
        }
    }
    return done[v] = ++t;
}

int main(){
    int N; cin>>N;
    G.resize(N);
    used.resize(N, 0);
    found.resize(N, 0);
    done.resize(N, 0);
    found[0] = 1;
    for(long long i=0; i<N; i++){
        int u, k; cin >> u >>k;
        u--;
        G[u].resize(k);
        for(long long j=0; j<k; j++){
            int v; cin >> v;
            v--;
            G[u][j] = v;
        }
    }
    int t = 1;
    for(long long i=0; i<N; i++){
        if(used[i]) continue;
        t = dfs(i, t) + 1;
    }
    for(long long i=0; i<N; i++){
        cout << i+1 << " " << found[i] << " " << done[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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;
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;
}

//スタックを用いたDFS
void dfs_visit(int r) {
    rep(i, n) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    rep(i, n) {
        color[i] = WHITE;
        nt[i] = 0;
    }

    tt = 0;

    //未訪問のuを始点としてDFS
    rep(u, n) {
        if(color[u] == WHITE) {
            dfs_visit(u);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    rep(i, n) {
        rep(j, n) {
            M[i][j] = 0;
        }
    }

    rep(i, n) {
        cin >> u >> k;
        u--;
        rep(j, k) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}

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

int adja[101][101];
int stamp1[101], stamp2[101];
int n, cur = 1;

void dfs(int u) {
    stamp1[u] = cur++;
    for (int i = 1; i <= n; ++i) {
        if (adja[u][i] && stamp1[i] == 0)
            dfs(i);
    }
    stamp2[u] = cur++;
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            adja[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (stamp1[i] == 0)
            dfs(i);
        cout << i << " " << stamp1[i] << " " << stamp2[i] << endl;
    }

    return 0;
}