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 <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

//#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG?????????????????????????????????????????????
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#define din cin
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUTFILE "output.txt" //*******************************************************************************************************************************************
#ifdef OUTPUTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
ofstream outputfile(OUTPUTFILE);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

//?¨??????\???????????????????????????????????????????????´??????INPUTFROMTEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define INPUTFILE "input.txt" //*******************************************************************************************************************************************
#ifdef INPUTFILE
#define din inputfile
ifstream inputfile(INPUTFILE);
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef unsigned long long ll;


const int INF = 999;//1e9-1;

int n;

//all array 1-based index
bool adjacencyMatrix[101][101] = {0};
int adjacencyList[101][101] = {0};

int currentTime = 1;
int discoveredTime[101] = {0};
int finishedTime[101] = {0};

int currentNode = 1;


void visit(int i) {
//    disp(src); disp(i);
//    dispAll(discoveredTime, n+3);
//    dispAll(finishedTime, n+3);
    
    if(discoveredTime[i]!=0) return;
    
    discoveredTime[i]=currentTime++;
    
    int j = 1;
    while(adjacencyList[i][j] != 0) {
//        disp(j);
//        disp(adjacencyList[i][j]);
        
        assert(j<=n);
        //??????????????¨??¨??§n?????§??????????????¨??????????????¨??????????????????list????????§??§???n-1??????????????°???????????§???0???n-1?????§???????????°??????adjacencyList[i][n]????????¶???0???????????????
        
        visit(adjacencyList[i][j]);
        j++;
    }
    
    finishedTime[i] = currentTime++;
    
    return;
}



int main() {
    din>>n;
    
    int s, g, numOfAdjacent;
    
    
    //input
    rep(i,1,n+1) {
        din>>s>>numOfAdjacent;
        
        rep(j,1,numOfAdjacent+1) {
            din>>g;
            adjacencyMatrix[s][g] = 1;
            adjacencyList[s][j] = g;
        }
    }
    
//    //test display
//    dout<<"   dist = ";
//    rep(j,1,n+1) dout<<j<<" ";
//    dout<<endl;
//    dout<<"          ";
//    rep(j,1,n+1) dout<<"-"<<" ";
//    dout<<endl;
//    
//    rep(i,1,n+1) {
//        dout<<"src = "<<i<<" | ";
//        rep(j,1,n+1) {
//            dout<<(j==1?"":" ")<<adjacencyMatrix[i][j];
//        }
//        dout<<endl;
//    }
//    
//    dout<<endl;
//    dout<<"                       ";
//    rep(j,0,n+1) disP(j);
//    dout<<endl;
//    dout<<"                       ";
//    rep(j,0,n+1) dout<<"  - ";
//    dout<<endl;
//    rep(i,1,n+1) {
//        disP(i); dispAll(adjacencyList[i], n+1);
//    }
    
    
    
    //DFS (Depth First Search)
    rep(i,1,n+1) {
        if(discoveredTime[i]==0) visit(i);
    }

//    dispAll(discoveredTime, n+1);
//    dispAll(finishedTime, n+1);
    
    
    //output
    rep(i,1,n+1) {
        dout<<i<<" "<<discoveredTime[i]<<" "<<finishedTime[i]<<endl;
    }
    
    
#ifdef INPUTFILE
    inputfile.close();
#endif
    
#ifdef OUTPUTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

C++: #include<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      e[u-1][v-1]=1;
    }
  }
  cnt=1;
  for(int i=0;i<n;i++)
    if(!used[i])dfs(i);
  
  for(int i=0;i<n;i++)
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;

  return 0;
}