Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <iostream>
#include <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int r){
    stack<int> S;

    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = -1;
        for (int j = 0; j < n; ++j){
            if(M[u][j] == 1 && color[j] == WHITE) {
                v = j;
                break;
            }
        }
        if (v != -1){
            S.push(v);
            color[v] = GRAY;
            d[v] = ++tt;
        } else {
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    int u;
    // initialization
    for( u = 0; u < n; ++u) color[u] = WHITE;
    tt = 0;

    for( u = 0; u < n; ++u){
        if (color[u] == WHITE) dfs_visit(u);
    }

    for( u = 0; u < n; ++u){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main()
{
    int u, v, k, i, j;
    scanf("%d", &n);

    for (i = 0; i < n; ++i){
        for(j = 0; j < n; ++j){
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; ++i){
        scanf("%d %d", &u, &k);
        --u;
        for (j = 0; j < k; ++j){
            scanf("%d", &v);
            --v;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

struct GraphParser {
  GraphParser(vector<vector<int>>& edges_)
      : edges(edges_), start(edges.size(), 0), end(edges.size(), 0) {
    //
  }

  void run() {
    t = 0;
    recur(0);
  }

  vector<vector<int>>& edges;
  vector<int> start;
  vector<int> end;
  int t;

 private:
  void recur(int cur) {
    if (start[cur]) {
      return;
    }
    start[cur] = ++t;
    for (auto&& e : edges[cur]) {
      recur(e);
    }
    end[cur] = ++t;
  }
};

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

  GraphParser p(edges);
  p.run();
  for (int i = 0; i < n; ++i) {
    cout << (i + 1) << " " << p.start[i] << " " << p.end[i] << endl;
  }
}

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