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 <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    for(int i = 0;i<c;i++)
    {
        if(v[i].first == 0)
            deep(i);
    }
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <stack>
#include <cstdio>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
stack<int> S;
int n;
int t=0;

int next(int u){
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1&&color[i]==WHITE) return i;
  }
  return NIL;
}

void dfs(int u){
  S.push(u);
  color[u]=GRAY;
  d[u]=++t;
  while(S.empty()==false){
    u=S.top();
    int v=next(u);
    if(v!=NIL){
      color[v]=GRAY;
      d[v]=++t;
      S.push(v);
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  dfs(1);
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

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

const int Max = 100;
const int white = 0;
const int gray = 1;
const int black = 2;

int n, M[Max][Max];
int color[Max], d[Max], f[Max], tt;
int nt[Max];

int next(int u){
    for(int v = nt[u]; v<n; v++){
        nt[u] = v+1;
        if(M[u][v]) return v;
    }
    return -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;
    }
    tt = 0;

    for(int u=00; 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;

    cin >> 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++){
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;

}

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

int main(){
	int n;
	cin >> n;

	int G[100][100]={0};

	for(int i=0; i<n; i++){
		int u,k;
		cin >> u >> k;
		
		for(int j=0 ; j<k; j++){
			int v;
			cin >> v;
	
			G[u-1][v-1] = 1;
		}
	}

	int d[100] = {0};
	int f[100] = {0};

	stack<int> S;
	int T=0;

	for(int i=0; i<n; i++){
		if(d[i]!=0)
			continue;
		S.push(i);
		d[i] = ++T;

		while(!S.empty()){
			int u = S.top();
			int v = -1;
			for(int j=0; j<n; j++){
				if(G[u][j]==1 && d[j]==0){
					v = j;
					break;
				}
			}

			if(v!=-1){
				S.push(v);
				d[v] = ++T;
			}else{
				S.pop();
				f[u] = ++T;
			}
		}
	}
	
	for(int i=0; i<n; i++){
		cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#define N 100
#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] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) 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>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<int,int> P;

vector<int> g[100];
int ans[100][2]; //[i][0] 到着　　[i][1] 終了
bool used[100];

int dfs(int v,int t){
	used[v] = true;
	ans[v][0] = t++;
	for(int i=0;i<g[v].size();i++){
		if(!used[g[v][i]]) t = dfs(g[v][i],t);
	}
	ans[v][1] = t;
	return t + 1;
}

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);

	int n;
	cin >> n;
	
	for(int i=0;i<n;i++){
		int u, nume;
		cin >> u >> nume;

		int v;
		for(int j=0;j<nume;j++){ //jは回数数えるだけ
			cin >> v;
			g[u-1].push_back(v-1);
		}
	}

	int t=1;
	for(int i=0;i<n;i++){
		if(!used[i]){
			t = dfs(i,t);
		}
	}

	for(int i=0;i<n;i++){
		cout << i+1 << " " << ans[i][0] << " " << ans[i][1] << "\n";
	}

	return 0;
}