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

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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 <bits/stdc++.h>
#define ll long long
using namespace std;

struct ver{
    ll d;
    ll f;
};

ll t=0;
vector<vector<ll>> mat;
vector<ver> vers;

void find(ll pos) {
    if(vers[pos].d == 0){
        t++;
        vers[pos].d = t;
    }
    for(ll i:mat[pos]) {
        find(i);
    }
    if(vers[pos].f == 0) {
        t++;
        vers[pos].f = t;
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        mat.push_back(aaa);
    }
    for(ll i=0;i<n;i++) {
        vers.push_back(ver{0,0});
    }
    find(0);
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<vers[i].d<<" "<<vers[i].f<<endl;
    }
}

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

bool rel[128][128];
int disc[128];
int comp[128];
int n, turn = 0;

void dfs(int visit, vector<int> log){
	log.push_back(visit);
	disc[visit] = ++turn;
	for(int i = 1; i <= n; i++){
		if(rel[visit][i] && find(log.begin(), log.end(), i) == log.end()) dfs(i, log);
	}
	comp[visit] = ++turn;
}

int main() {
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		int u, k;
		scanf("%d %d", &u, &k);
		
		for(int j = 1; j <= n; j++){
			rel[u][j] = false;
		}
		while(k--){
			int v;
			scanf("%d", &v);
			rel[u][v] = true;
		}
	}
	
	vector<int> visited;
	dfs(1, visited);
	
	for(int i = 1; i <= n; i++){
		printf("%d %d %d\n", i, disc[i], comp[i]);
	}
	return 0;
}

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

int search(int idx, std::vector<std::vector<int>> vec, std::vector<int>& s, std::vector<int>& d, int t) {
	if (d[idx] != 0 || s[idx] != 0) return t - 1;
	if (s[idx] == 0) s[idx] = t;
	for (int i = 0; i < vec[idx].size(); i++) {
		if (idx == vec[idx][i] - 1) continue;
		t = search(vec[idx][i] - 1, vec, s, d, t + 1);
	}
	d[idx] = ++t;
	return t;
}

int main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int>> vec(n);
	std::vector<int> s(n, 0);
	std::vector<int> d(n, 0);
	for (int i = 0; i < n; i++) {
		int u, k;
		std::cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int a;
			std::cin >> a;
			vec[u - 1].push_back(a);
		}
	}

	int t = 0;
	for (int i = 0; i < n; i++) {
		t = search(i, vec, s, d, t + 1);
	}
	// output
	for (int i = 0; i < n; i++) {
		std::cout << i + 1 << " " << s[i] << " " << d[i] << std::endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <stack>
#include <map>

using namespace std;

template<typename ISTREAM>
void readGraphListAsMatrix(const size_t n, ISTREAM& cin, vector< vector<int> >& graphMatrix) {
	graphMatrix = vector< vector<int> >(n, vector<int>(n, 0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u;
		cin>> k;
		for (size_t j = 0; j != k; ++j) {
			size_t v;
			cin >> v;
			graphMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
}

void printMatrix(const vector< vector<int> >& grapthMatrix) {
	const size_t n = grapthMatrix.size();
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}
}


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > graphMatrix;
	readGraphListAsMatrix(n, cin, graphMatrix);
	stack<int> visitedNodeIDs;
	int time = 0;
	vector<pair<int, int>> timeStamp(n,make_pair(0,0));//pair<初回訪問時刻, 完了時刻>
	vector<vector<int>::iterator> searchBeginPos; {
		searchBeginPos.reserve(n);
		for (auto& v : graphMatrix)searchBeginPos.push_back(v.begin());
	}

	vector<pair<int, int>>::iterator visitTimeSearchPos = timeStamp.begin();
	while (
		(visitTimeSearchPos = find_if(visitTimeSearchPos, timeStamp.end(), [&](const pair<int, int>& df) {return df.first == 0; }))
		!= timeStamp.end()) {
		const size_t firstVisitNodeID_1 = distance(timeStamp.begin(), visitTimeSearchPos);
		visitedNodeIDs.push(firstVisitNodeID_1);
		visitTimeSearchPos->first = ++time;
		for (auto&v : graphMatrix) v.at(firstVisitNodeID_1) = 0;
		++visitTimeSearchPos;
		while (!visitedNodeIDs.empty()) {
			const int nodeID_1 = visitedNodeIDs.top();
			vector<int>& neighbourNodeList = graphMatrix.at(nodeID_1);
			vector<int>::iterator result = find(searchBeginPos.at(nodeID_1), neighbourNodeList.end(), 1);
			if (result != neighbourNodeList.end()) {
				const int nextVisitID_1 = distance(neighbourNodeList.begin(), result);
				timeStamp.at(nextVisitID_1).first = time + 1;
				for (auto&v : graphMatrix) v.at(nextVisitID_1) = 0;
				visitedNodeIDs.push(nextVisitID_1);
				searchBeginPos.at(nodeID_1) = result + 1;
			}
			else {
				//隣接リストに検索対象なし
				timeStamp.at(nodeID_1).second = time + 1;
				visitedNodeIDs.pop();
			}
			++time;
		}
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << timeStamp.at(i).first << " " << timeStamp.at(i).second << endl;
	}
}


int main()
{
	execute(cin);

	return 0;
}

C++: #include <stdio.h>
#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 u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt; // 最初の訪問
  for (v = 0; v < n; v++)
  {
    if (M[u][v] == 0)
      continue;
    if (color[v] == WHITE)
    {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

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

  for (u = 0; u < n; u++)
  {
    // 未訪問の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 (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      M[i][j] = 0;
    }
  }

  for (int 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;
}