Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

void dfs(int cur);

int A[100][100], d[100], f[100];;
int n,t=0;

int main()
{
    	cin>>n;
        
    	for(int i=0;i<n;++i){

		d[i]=0;
		f[i]=0;

        	for(int j=0;j<n;++j){
            		A[i][j]=0;
        	}
        
        	int m,k; //k=number of adj
        	cin>>m>>k;
        	assert(m==i+1);
        
        	for(int j=0;j<k;++j){
            		int adj;
            		cin>>adj;
            		if(adj){
                		A[i][adj-1]=1;
            		}
        	}
    	}

	dfs(0);

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

    	return 0;
}

void dfs(int cur)
{
	t+=1;
	d[cur]=t;

	for(int dst=0;dst<n;++dst){
		if(A[cur][dst]==1&&d[dst]==0){
			dfs(dst);
		}
	}

	t+=1;
	f[cur]=t;

	return;
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

void dft(vector<vector<int>> graph, vector<vector<int>>& time, int v, int& t){
    for(int i=0; i<graph[v].size(); i++){
        int next_v = graph[v][i];
        if(time[next_v][0] == 0){
            time[next_v][0] = t;
            t++;
            dft(graph, time, next_v, t);
        }
    }
    time[v][1] = t;
    t++;
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<vector<int>> graph(n+1);

    for(int i=1; i<=n; i++){
        int u, k;
        cin >> u >> k;
        for(int j=0; j<k; j++){
            int v;
            cin >> v;
            graph[i].push_back(v);
        }
    }

    vector<vector<int>> time(n+1, vector<int>(2, 0));
    int v = 1, t = 1;

    while(v <= n){
        time[v][0] = t;
        t++;
        dft(graph, time, v, t);

        for(; v<=n; v++){
            if(time[v][0] == 0){
                break;
            }
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N] = {0};
int color[N] = {0}, d[N], f[N], tt = 0;
int nt[N] = {0};

void dfs_visit(int r);
void dfs();
int next(int u);

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

void dfs_visit(int r) {

	int u, v;

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

	while (!S.empty()) {
		u = S.top();
		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;
		}
	}
}

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

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 << " " << d[i] << " " << f[i] << endl;
	}
}

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

struct node
{long long v; struct node *next;};

struct node *z;

void visit(long long k,  struct node **adj, long long &time, long long d[], long long f[]){
    struct node *t;
    d[k] = ++time;
    for(t = adj[k]; t != z; t = t -> next){
        if(d[t -> v] == 0) visit(t -> v, adj, time, d, f);
    }
    f[k] = ++time;
}
void search(long long V, struct node **adj, long long &time, long long d[], long long f[]){
    long long k;
    for(k = 1; k <= V; k++) d[k] = 0;
    for(k = 1; k <= V; k++){
        if(d[k] == 0) visit(k, adj, time, d, f);
    }
}

int main(){

    //adjacency list representation
    long long V, E;
    cin >> V;
    struct node *adj[V + 1];
    long j, k, x, y[V + 1];
    struct node *t;
    z = new node;
    z -> next = z;
    for(j = 1; j <= V; j++) adj[j] = z;
    for(j = 1; j <= V; j++){
        cin >> x >> E;
        for(k = 1; k <= E; k++){
            cin >> y[k];
        }
        for(k = E; k >= 1; k--){
            t = new node;
            t -> v = y[k];
            t -> next = adj[x];
            adj[x] = t;
        }
    }

    //depth first search
    long long time = 0;
    long long d[V + 1];
    long long f[V + 1];
    search(V, adj, time, d, f);
    for(j = 1; j <= V; j++){
        cout << j << " " << d[j] << " " << f[j] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int adj[105][105] = {0};
int res[105][2] = {0};
int t = 1;
int n;

int dfs(int start){
    if(res[start][0] == 0)
        res[start][0] = t;
    t++;
    REP(i, n)
        if(adj[start][i] != 0 && res[i][0] == 0)
            dfs(i);
    res[start][1] = t;
    t++;
    return 0;
}

int main() {
    cin >> n;
    REP(i, n){
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            adj[u-1][tmp-1] = 1;
        }
    }
    REP(i, n)
        if(res[i][0] == 0)
            dfs(i);
    REP(i, n)
        cout << i+1 << " " << res[i][0] << " " << res[i][1] << endl;
    return 0;
}