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<stack>
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];
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;
}
//用栈实现的深度优先搜索 
void dfs_visit(int r){
	for(int i = 0;i < n;i++){
		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(){
	//初始化 
	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,v,k;
	cin >> n;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			M[i][j] = 0;
		}
	}
	
	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 <cstring>
#include <iostream>

static int tp = 1;
static int n;

void depth_first(int node, int *start_ts, int *end_ts, int **adj_list) {
    start_ts[node] = tp;
    tp++;
    for (int i = 0; adj_list[node][i] != -1; i++) {
        int dst = adj_list[node][i];
        if (start_ts[dst] != 0) {
            continue;
        }
        depth_first(dst, start_ts, end_ts, adj_list);
    }
    end_ts[node] = tp;
    tp++;
}

int main() {
    std::cin >> n;
    int *adj_list[n];

    int u, k, v;
    for (int i = 0; i < n; i++) {
        std::cin >> u >> k;
        adj_list[u - 1] = new int[k + 1];
        for (int j = 0; j < k; j++) {
            std::cin >> v;
            adj_list[u - 1][j] = v - 1;
        }
        adj_list[u - 1][k] = -1;
    }

    int start_ts[n], end_ts[n];
    memset(start_ts, 0, sizeof(int) * n);
    for (int i = 0; i < n; i++) {
        if (start_ts[i] == 0) {
            depth_first(i, start_ts, end_ts, adj_list);
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << start_ts[i] << " " << end_ts[i] << std::endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 105;
int cnt = 1;
vector<vector<int>> Graph(n,vector<int>());
vector<bool> visited(n,0);
vector<int> first(n);
vector<int> last(n);

void dfs(int i,int &cnt ){
        //行き
        first.at(i) = cnt;
        cnt ++;
        visited.at(i) = 1;
        
        for(auto p:Graph.at(i)){
                if(visited.at(p)) continue;
                dfs(p,cnt);
        }
        
        //帰り
        last.at(i) = cnt;
        cnt ++;
}

int main(){
        int n;
        cin >>n;
        rep(i,n){
                 int u,k;
                cin >> u >> k;
                --u;
                rep(j,k){
                         int p;
                        cin >> p;
                        --p;
                        Graph.at(u).push_back(p);
                }
        }
        rep(i,n){
                 if(!visited.at(i)) dfs(i,cnt);
        }
        rep(i,n){
                 cout << i+1 <<" ";
                cout << first.at(i) << " ";
                cout << last.at(i) << endl;
        }
        

        return 0;
}

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

using namespace std;

void dfs(int v,vector<vector<int>>& vertex, int d[], int f[]);

int cnt = 1;

int main(){
    int n;
    cin >> n;
    int num;
    int tmp2;
    int d[n] = {};
    int f[n] = {};
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2-1);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    dfs(0, vertex, d, f);
    for(int i=0;i<n;i++){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " <<  d[i] << " " << f[i] << endl;
    }
    return 0;
}

void dfs(int v, vector<vector<int>>& vertex, int d[], int f[]){
    d[v] = cnt++;
    for(int i : vertex[v]){
        if(d[i]==0){
            dfs(i, vertex, d, f);
        }
    }
    f[v] = cnt++;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int main ()
{
    int N;
    cin >> N;

    int M[N][N];
    int D[N], F[N], C[N];

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}