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 <vector>
#include <stack>
#include <utility>

using vvb = std::vector<std::vector<bool>>;

struct TimeStamp
{
    int discovered;
    int finished;
};

std::vector<TimeStamp> dfs(const vvb& edges)
{
    using namespace std;

    int time {1};
    const int n = edges.size();
    stack<int> st;
    vector<bool> reached(n);
    vector<TimeStamp> times(n);

    //すべての辺について行う
    for (int i = 0; i < n; ++i)
    {
        if (reached[i])
            continue;

        reached[i] = true;
        times[i].discovered = time++;
        st.push(i);
        
        //点jからつながるすべての辺を調べる
        while (!st.empty())
        {
            int top = st.top();
            for(int j = i + 1; j < n; ++j)
                if (!reached[j] && edges[top][j])
                {
                    reached[j] = true;
                    times[j].discovered = time++;
                    st.push(j);
                    break;
                }

            //その点からの探索候補がなければ前の点に戻る
            if (top == st.top())
            {
                times[top].finished = time++;
                st.pop();
            }
        }
    }

    return times;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    vvb edges(n, vector<bool>(n));

    //読み込み
    for (int i = 0; i < n; ++i)
    {
        int u, k;
        cin >> u >> k;

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

    auto times = dfs(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i + 1 << " " << times[i].discovered << " " << times[i].finished << endl;
    }
}

int main()
{
    solve();
    return 0;
}

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

int n;
vector< vector<int> > do_thi; 
bool *da_duyet;
int *d;
int *f;
int timestamp;

void dfs(int dinh_dang_duyet) { 
	d[dinh_dang_duyet] = timestamp++; // Danh dau so buoc bat dau duyet dinh
	da_duyet[dinh_dang_duyet] = true; // Danh dau dinh da duoc duyet
	// Tim nhung dinh lan can
	for (int i = 0, lan_can = 0; i < do_thi[dinh_dang_duyet].size(); ++i) {
		lan_can = do_thi[dinh_dang_duyet][i];
		if (da_duyet[lan_can]) continue;
		dfs(lan_can);
	}
	f[dinh_dang_duyet] = timestamp++; // Danh dau so buoc khi ket thuc viec duyet dinh do
}

int main() {
	cin >> n; // Sau khi co gia tri n cu the moi cap phat kich thuoc o nho cho cac mang
	da_duyet = new bool[n + 1]; // Cap phat mang danh dau dinh da duyet hay chua (vi mang chi so tinh tu 0)
	d = new int[n + 1]; // Cap phat mang de luu thoi diem tim ra cac dinh
	f = new int[n + 1]; // Cap phat mang de luu thoi diem duyet xong cac dinh
	
	for (int i = 0; i <= n; ++i) { // Khoi tao cac gia tri cho moi dinh
		do_thi.push_back(vector<int>()); // Khoi tao vector cho moi dinh
		da_duyet[i] = false; // Khoi tao trang thai da duyet hay chua cho moi dinh
		d[i] = 0; // Khoi tao thoi diem tim ra moi dinh
		f[i] = 0; // Khoi tao thoi diem duyet xong moi dinh
	}
	for (int i = 0, k = 0, u = 0, v = 0; i < n; ++i) { // Xay dung cac canh cua do thi
		cin >> u; // Doc vao ID cua dinh u
		cin >> k; // Doc vao so dinh ke voi u (bac cua dinh u)

		for (int j = 0; j < k; ++j) { // Doc vao cac dinh lan can cua u, dua vao do thi
			cin >> v; // Doc vao moi dinh lan can
			do_thi[u].push_back(v); // Dua vao vector bieu dien tinh tuong ung
		}
	}
	
//	for (int i = 1; i <= n; ++i) { // Sap xep lai cac dinh lan can cua dinh i
//		sort(do_thi[i].begin(), do_thi[i].end());
//	}
	
	timestamp = 1;
	
	for (int i = 1; i <= n; ++i) { // Duyet tat ca cac dinh cua do thi
		if (da_duyet[i]) continue; // Neu dinh da duyet thi kiem tra tiep
		dfs(i);	// Neu dinh chua duyet thi dua vao ham dfs
	}
	
	for (int i = 1; i <= n; ++i) { // In ra ket qua
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

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

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != n-1) cout << B[i][j] << " ";
            else cout << A[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

int n, t;
int v[100][100];
int d[100], f[100];

void stamp(int id) {
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = n - 1; i > -1; i--)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i < 0 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			int j;
			for (j = n - 1; j > -1; j--)
				if (v[j][id - 1] == 1 && f[j] == 0 && d[j] != 0)
					stamp(j + 1);
			if (j < 0) {
				int k = 0;
				while (d[k] != 0)
					k++;
				if (k < n)
					stamp(k + 1);
			}
		}
	}
	else	
		return;
}

int main()
{
	cin >> n;

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

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

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

	t = 1;
	stamp(1);

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

	return 0;
}