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>

using namespace std;

static const int MAX = 100;
static const int WHITE = 1;
static const int GRAY = 2;
static const int BLACK = 3;
static const int NIL = -1;

class DFS{
private:
    int color[MAX];
    int M[MAX][MAX];
    stack<int> S;
    int n;
    int discovery[MAX];
    int finish[MAX];
    int time = 0;
    int next_vertex[MAX];
public:
    DFS()
    {
        cin >> n;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                M[i][j] = 0;
        int vertex;
        int degree;
        for(int i = 0; i < n; i++)
        {
            color[i] = WHITE;
            next_vertex[i] = 0;
            cin >> vertex;
            cin >> degree;
            int to_v;
            for(int j = 0; j < degree; j++)
            {
                cin >> to_v;
                M[vertex - 1][to_v - 1] = 1;
            }
        }
    }

    int next(int u)
    {
        for(int v = next_vertex[u]; v < n; v++)
        {
            next_vertex[u] = v + 1;
            if(M[u][v]) return v;
        }
        return NIL;
    }

    void dfs_visit(int start)
    {
        for(int i = 0; i < n; i++)
            next_vertex[i] = 0;

        S.push(start);
        color[start] = GRAY;
        discovery[start] = ++time;

        while(S.size() != 0)
        {
            int u = S.top();
            int v = next(u);
            if(v != NIL)
            {
                if(color[v] == WHITE)
                {
                    color[v] = GRAY;
                    discovery[v] = ++time;
                    S.push(v);
                }
            }
            else
            {
                S.pop();
                color[u] = BLACK;
                finish[u] = ++time;
            }
        }
    }

    void dfs()
    {
        for(int u = 0; u < n; u++)
        {
            if(color[u] == WHITE)
                dfs_visit(u);
        }

        for(int i = 0; i < n; i++)
            cout << i + 1 << " " << discovery[i] << " " << finish[i] << endl;
    }
};

int main()
{
    DFS dfs;
    dfs.dfs();
}

C++: #include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}


int t = 1;
void dfs(const vector<vector<int> > &G, int v, vector<bool> &seen, VI &d, VI &f) {
    seen[v] = true; // v を訪問済にする
    d[v] = t;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v] == false) { // next_v が探索済だったらスルー
          	t++;
        	dfs(G, next_v, seen, d, f); // 再帰的に探索     	
        }
    }
    t++;
    f[v] = t;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int n, u, k;
    cin >> n;
    VVI G(n);
    REP(i,n){
        cin >> u >> k;
        if (k){
            G[i].resize(k);
            REP(j,k) {
                cin >> G[i][j];
                G[i][j]--;
            }
          	sort(ALL(G[i]));
        }
    }

    vector<bool> seen(n,false);

    VI d(n,0), f(n,0);

  	REP(i,n){
      	if (d[i] == 0){
        	dfs(G, i, seen, d, f);
          	t++;
        }
    }

    REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;

}

C++: #include <cstdio>

typedef struct Node {
    int id;
    int d;
    int f;
    int count;
} Node;


int count(int id, int now, Node *node, int a[101][100]){
    if(node[id].d == 0) node[id].d = now;
    else return now - 1;
    if(node[id].f != 0) return now - 1;
    for(int i = 0; i < node[id].count; ++i){
        int nextId = a[id][i];
        now = count(nextId, now + 1, node, a);
    }
    node[id].f = now + 1;
    return node[id].f;
}

int main(){
    int n;
    std::scanf("%d", &n);
    Node node[101];
    int a[101][100];
    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        node[id].id = id;
        std::scanf("%d", &node[id].count);
        for(int j = 0; j < node[id].count; ++j){
            std::scanf("%d", &a[id][j]);
        }
    }
    int now = 0;
    for(int i = 1; i <= n; ++i){
        now = count(i, now + 1, node, a);
    }
    for(int i = 1; i <= n; ++i){
        std::printf("%d %d %d\n", node[i].id, node[i].d, node[i].f);
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define N 105
int n,cnt;
int graph[N][N];
int ans1[N],ans2[N];
bool checked[N];
void dfs(int i){
    if(checked[i]) return;
    checked[i] = true;
    ans1[i] = cnt++;
    for(int j = 0; j < n; j++){
        if(graph[i][j]) dfs(j);
    }
    ans2[i] = cnt++;
}

signed main() {
    cin >> n;
    for(int i = 0; i < n; i++){
        int a,b,c;
        cin >> a >> b;
        a--;
        for(int j = 0; j < b; j++){
            cin >> c;
            c--;
            graph[a][c] = 1;
        }
    }

    cnt = 1;
    for(int i = 0; i < n; i++){
        if(!checked[i]) dfs(i);
    }
    for(int i = 0; i < n; i++){
        cout << i + 1 << " " << ans1[i] << " " << ans2[i] << endl;
    }
}