Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void dfs(int now, vector<vector<int>>& path, vector<int>& find, vector<int>& finish, int& time) {
		find[now] = time++;
		REP(i, path[now].size()) {
			int t = path[now][i];
			if (find[t] < 0) {
				dfs(t, path, find, finish, time);
			}
		}
		finish[now] = time++;
	}

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<vector<int>> path(n);
		REP(i, n) {
			int u, k;
			cin >> u >> k;
			u--;
			REP(j, k) {
				int v;
				cin >> v;
				v--;
				path[u].push_back(v);
			}
		}
		vector<int> visit(n, 0);
		vector<int> find(n, -1);
		vector<int> finish(n, -1);
		int time = 1;
		REP(i, n) {
			if (find[i] < 0) {
				dfs(i, path, find, finish, time);
			}
		}
		REP(i, n) {
			put(i + 1, find[i], finish[i]);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	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++){
        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++: #include <iostream>
using namespace std;

enum Color {
	WHITE,
	GRAY,
	BLACK,
};

class dfs {
public:
	dfs(bool matrixT[][100], Color colorT[], int ts_F[], int ts_L[], int verNum) {
		for (int i = 0; i < verNum; i++) {
			for (int j = 0; j < verNum; j++)
				matrixTable[i][j] = matrixT[i][j];
		}
		verNumber = verNum;
	}

	void DFS(int nowVerVal) {
		colorTable[nowVerVal] = GRAY;
		++ttl;
		ts_first[nowVerVal] = ttl;

		for (int nextVer = 0; nextVer < verNumber; nextVer++) {
			if (matrixTable[nowVerVal][nextVer] == false) continue;
			if (colorTable[nextVer] != WHITE) continue;
			DFS(nextVer);
		}
		colorTable[nowVerVal] = BLACK;
		++ttl;
		ts_last[nowVerVal] = ttl;
	}

	void DFS_Init() {
		ttl = 0;
		for (int i = 0; i < verNumber; i++)
			colorTable[i] = WHITE;

		for (int i = 0; i < verNumber; i++)
			if (colorTable[i] == WHITE) DFS(i);
	}

	void print() {
		for (int i = 0; i < verNumber; i++) {
			cout << i + 1 << " " << ts_first[i] << " " << ts_last[i] << endl;
		}
	}
private:
	bool matrixTable[100][100];
	Color colorTable[100];
	int ts_first[100];
	int ts_last[100];
	int verNumber;
	int ttl;
};

int main() {
	int verNum; //num??????????????°???value????????????????????????????????¨???
	bool matrixTable[100][100]; //???????????¨??????????????????
	Color colorTable[100];
	int timeStamp_first[100];
	int timeStamp_last[100];
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++) {
			matrixTable[i][j] = false;
		}

	for (int i = 0; i < verNum; i++) {
		int verVal, nextVerNum;
		cin >> verVal >> nextVerNum;
		for (int j = 0; j < nextVerNum; j++) {
			int nextVerVal;
			cin >> nextVerVal;
			//0?????????????????´???
			matrixTable[verVal - 1][nextVerVal - 1] = true;
		}
	}

	dfs* d = new dfs(matrixTable, colorTable, timeStamp_first, timeStamp_last, verNum);
	d->DFS_Init();
	d->print();

	return 0;
}

C++: #include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
//   訪問状態     発見    完了
int n,M[101][101];
const int WHITE=0; //未訪問
const int GRAY=1;  //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(int j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) //訪問していないか
      dfs(i); //iを始点に
  }
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}