Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> d;
vector<int> f;
int t;
void dfs(vector<vector<int>>Graph, int v) {
  d[v] = t;
  t++;
  if(Graph[v].size() == 0) {
    return;
  }
  for(auto next_v: Graph[v]) {
    if(d[next_v] != -1) {
      continue;
    }
    //cout << next_v << ":" << t << endl;
    dfs(Graph, next_v);
    f[next_v] = t;
    t++;
  }
  f[v] = t;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> Graph(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int a;
      cin >> a;
      Graph[i].push_back(a-1);
    }
  }
  d = f = vector<int>(n, -1);
  d[0] = 1;
  t = 1;
  dfs(Graph, 0);
  f[0] = t;
  rep(i, n) {
    if(d[i] == -1) {
      t++;
      dfs(Graph, i);
      //f[i] = t;
    }
  }
  rep(i, n) {
    cout << i + 1 << " ";
    cout << d[i] << " ";
    cout << f[i] << endl;
  }
}

C++: /* 深さ優先探索
 １．一番最初に訪問する頂点をスタックに入れる
 ２．スタックに頂点が積まれている限り...
 　- スタックのトップにある頂点uを訪問する
   - 現在訪問中の頂点uから次の頂点vへ移動する時に、vをスタックへ積む。
   　uに未訪問の隣接する頂点がなければuをスタックから削除する
*/

#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; // 隣接する頂点vを返す
	}
	return -1; // 隣接する頂点がないなら-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; // 経過時刻を表すタイムスタンプを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, k, v; // 訪問中の頂点u, 次数k, 次に訪問する頂点v

	cin >> n;
	for (int i = 0; i < n; i++) { // 配列0で初期化
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}

	// 無向グラフを作成
	for (int i = 0; i < n; i++) {
		cin >> u >> k; // 頂点uと出次数kを入力
		u--; // 1 -> 0オリジンに変換
		for (int j = 0; j < k; j++) {
			cin >> v; // 次に訪問する未訪問頂点v入力
			v--; // 0オリジンへ変換
			M[u][v] = 1;
		}
	}

	dfs();

	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++){
        printf("%d %d %d\n", i, found[i], comp[i]);
    }
    return 0;
}

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

using namespace std;

static const int N = 100;
static const int NEW = 0;
static const int VISITING = 1;
static const int OLD = 2;

int n, m[N][N] = {0}, t;
int color[N] = { 0 }, t1[N] = { 0 }, t2[N] = {0};

void getMatrix()
{
	int u, v, k;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			cin >> v;
			m[u-1][v-1] = 1;
		}
	}
}

int nxt(int idx)
{
	for (int i = 0; i < n; ++i)
	{
		if (1 == m[idx][i] && color[i] == NEW)
			return i;
	}
	return -1;
}

void dfs_visit(int idx)
{
	stack<int> s;
	s.push(idx);
	color[idx] = VISITING;
	t1[idx] = t++;


	while (!s.empty())
	{
		int u = s.top();
		int v = nxt(u);
		if (-1 != v)
		{
			if (color[v] == NEW)
			{
				color[v] = VISITING;
				t1[v] = t++;
				s.push(v);
			}
		}
		else
		{
			s.pop();
			color[u] = OLD;
			t2[u] = t++;
		}
	}
}

void dfs()
{
	t = 1;

	for (int i = 0; i < n; ++i)
		color[i] = NEW;

	for (int i = 0; i < n; ++i)
	{
		if (color[i] == NEW)
			dfs_visit(i);
	}

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

int main()
{
	getMatrix();
	dfs();
}