Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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

bool M[100][100];
int n,m,num;
int color[100], d[100], f[100], tt,mark[100];

int next(int u) {
	for (int i = mark[u]; i < n; i++) {
		if (M[u][i] != 0) {
			mark[u] = i + 1;
			return i;
		}
	}
	return -1;
}

void dfs_visit(int r) {
	stack<int> s;
	s.push(r);
	d[r] = ++tt;
	color[r] = 1;

	while (!s.empty()){
		int v = s.top();
		int k = next(v);
		if (k != -1) {
			if (color[k] == 0) {
				color[k] = 1;
				d[k] = ++tt;
				s.push(k);
			}
		}
		else {
			color[v] = 2;
			f[v] = ++tt;
			s.pop();
		}
	}




}




int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> m;
		cin >> m;
		for (int v = 0; v < m; v++) {
			cin >> num;
			M[i - 1][num-1] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		if (color[i] == 0) {
			dfs_visit(i);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i]<< endl;
	}
	
}

C++: #include<stdio.h>
#define MAX 100

int adj[MAX][MAX];/*隣接行列*/
int d[MAX];/*発見時刻*/
int f[MAX];/*終了時刻*/
int flg[MAX];/*ノード訪問したかどうか*/
int time=0;

void dfs(int u,int n){
	
	flg[u]=1;
	d[u]=++time;
	
	for(int i=0;i<n;i++){
		if(adj[u][i] && !flg[i]){/*ノードuから到達可能かつ未訪問*/
			dfs(i,n);
		}
	}
	f[u]=++time;
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		flg[i]=0;
		for(j=0;j<n;j++)
			adj[i][j]=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			adj[x-1][z-1]=1;
		}
	}
	
	for(i=0;i<n;i++)
		if(!flg[i])
			dfs(i,n);
	
	
	for(i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
	
	return 0;
	
}

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;
	visitedNodeIDs.push(0);
	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());
	}
	timeStamp.at(0).first = 1;
	while (!visitedNodeIDs.empty()) {
		++time;
		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();
		}
	}
	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<iostream>
using namespace std;

int d[101]={0};
int f[101]={0};
int AdjM[101][101]={0};
int lapse=0;

void dfs(int cur){
    ++lapse;
    d[cur]=lapse;
    //cerr<<"visiting "<<cur<<" "<<lapse<<"\n";
    for(int dst=1;dst<101;++dst){
        if(AdjM[cur][dst]!=0 && d[dst]==0){
            dfs(dst);
        }
    }
    ++lapse;
    f[cur]=lapse;
}

int main(){
    int N;
    cin>>N;
    int id,edgnum,adj;
    for(int i=0;i<N;++i){
        cin>>id>>edgnum;
        for(int j=0;j<edgnum;++j){
            cin>>adj;
            AdjM[id][adj]+=1;
        }
    }

    for(int i=1;i<=N;++i){
        if(d[i]==0){
            dfs(i);
        }
    }

    for(int i=1;i<=N;++i){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<"\n";
    }
}