Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

#define endl '\n'
#define ll long long
#define ui unsigned int
#define ull unsigned long long

int main(void)
{
    int n;
    while (cin >> n)
    {
        int adj[10][10]={{0}};
        int tmpn = n;
        while (tmpn--)
        {
            int u, k;
            cin >> u >> k;
            for (int i = 0 ; i < k ; i++)
            {
                int tmp;
                cin >> tmp;
                adj[u-1][tmp-1] = 1;
            }
        }

        stack<int> stk;
        int g[10]={0}, f[10]={0};
        g[0] = 1;
        int current = 2;
        int isEnd = 1;

        stk.push(1);
        while (!stk.empty())
        {
            int now = stk.top();
            for (int i = 0 ; i < n ; i++)
            {
                if (adj[now-1][i] == 1 && g[i] == 0)
                {
                    stk.push(i+1);
                    g[i] = current++;
                    isEnd = 0;
                }
            }
            if(isEnd)
            {
                if (g[now-1] == 0)
                {
                    g[now-1] = current++;
                }
                f[now-1] = current++;
                stk.pop();
            }
            isEnd = 1;
        }
        for (int i = 0 ; i < n ; i++)
        {
            cout << i+1 << " " << g[i] << " " << f[i] << endl;
        }

    }
    return 0;
}

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

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &e);
        for(j = 1; j <= e; j++){
            scanf("%d", &b); G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

    for(i = 1; i <= n; i++){
        cout << i << " " << found[i] << " " << comp[i] << endl;
    }
    return 0;
}

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

int N;
int G[101][101];
int visited[101];

int start[101], complete[101];

int dfs(int v, int t) {
    visited[v] = 1;
    start[v] = t;
    int nt = t+1;
    for (int j = 0; j <= N; ++j) {
        if (!visited[j] && G[v][j]) {
            nt = dfs(j, nt);
        }
    }
    complete[v] = nt;
    return nt+1;
}

int main() {
    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int j = 0; j <= N; ++j) visited[j] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int tt = 1;
    for (int j = 1; j <= N; ++j) {
        if (!visited[j]) tt = dfs(j, tt);
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << start[j] << " " << complete[j] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], f[101];
int t = 0;

void dfs(int u, int n)
{
	color[u] = 1;
	d[u] = ++t;
	for (int v = 1; v <= n; v++) {
		if (G[u][v] && color[v] == 0)
			dfs(v, n);
	}
	color[u] = 1;
	f[u] = ++t;
}

int main(void)
{
	int n, k, v, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (color[i] == 0)
			dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}