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<stack>
//#include "stdio.h"

using namespace std;

#define N 100

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

int n, M[N][N];
int color[N],d[N],f[N];
int world_time;

int next(int node){
  for(int v=0;v<n;v++){
    if(M[node][v] == 1 && color[v] == WHITE){
      return v;
    } 
  }
  return NIL;
}

void dfs_visit(int i){
  
  world_time = world_time + 1;
  stack<int> S;
  S.push(i);
  color[i] = GRAY;
  d[i] = world_time;

  int present,next_node;
  while( !S.empty() ){
    world_time = world_time + 1;
    present = S.top();
    next_node = next(present);

    if(next_node != NIL){
      S.push(next_node);
      d[next_node] = world_time;
      color[next_node] = GRAY;
    }else{
      color[present] = BLACK;
      S.pop();
      f[present] = world_time;
    }
  }
}

void dfs(){
  world_time = 0;

  for(int i=0;i<n;i++){
    color[i] = WHITE;
  }

  for(int i=0;i<n;i++){
    if(color[i] == WHITE){
      dfs_visit(i);
    }
  }

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


int main(void){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j] = 0;
    }
  }

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

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

  dfs();

  return 0;
}

C++: #include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
int a[105][105];
int tim=0;
int first[105],last[105];
int zhuangtai[105];
int us;
int nex[105];
int findnext(int k)
{
    for(int i=nex[k];i<us;i++)
    {
        nex[k]=i+1;
        if(a[k][i]) return i;
    }
    return -1;
}
void visit(int k)
{
    for(int i=0;i<us;i++)
    {
        nex[i]=0;
    }
    stack<int > s;
    s.push(k);
    first[k]=++tim;
    zhuangtai[k]=1;
    while(!s.empty())
    {
        int n=s.top();
        int ne=findnext(n);
        if(ne!=-1)
        {
            if(zhuangtai[ne]==0){
                zhuangtai[ne]=1;
                first[ne]=++tim;
                s.push(ne);
            }
        }else{
            s.pop();
            zhuangtai[n]=2;
            last[n]=++tim;
        }
    }
}
void dfs()
{
    for(int i=0;i<us;i++)
    {
        zhuangtai[i]=0;
        nex[i]=0;
    }
    for(int i=0;i<us;i++)
    {
        if(zhuangtai[i]==0) visit(i);
    }
    for(int i=0;i<us;i++)
    {
        printf("%d %d %d\n",i+1,first[i],last[i]);
    }
}
int main()
{
    scanf("%d",&us);
    for(int i=0;i<us;i++)
    {
        int p,x;
        scanf("%d%d",&p,&x);
        p--;
        for(int j=0;j<x;j++)
        {
            int y;
            scanf("%d",&y);
            y--;
            a[p][y]=1;
        }
    }
    dfs();
    return 0;
}

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

int G[105][105]={};
int d[105]={},f[105]={};
int N,T=0;

void Gprint(int n){
    cout<<"\\|";
    for(int i=0; i<n; i++)cout<<i+1;
    cout<<endl;
    for(int i=0; i<n+2; i++)cout<<"-";
    cout<<endl;
    for(int i=0; i<n; i++){
        cout<<i+1<<"|";
        for(int j=0; j<n; j++){
            cout<<G[i][j];
        }
        cout<<endl;
    }
}

void dfs(int n){
    if(d[n])return;
    d[n]=++T;
    for(int i=0; i<N; i++){
        if(G[n][i])dfs(i);
    }
    f[n]=++T;
}

int main(){
    int u,k,v;

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

//    Gprint(N);

    for(int i=0; i<N; i++)
        dfs(i);

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

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n,t = 0;
int color[100],d[100],f[100],M[100][100];
int nt[100];

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] = ++t;

  while(!S.empty()) {
    int u = S.top();
    int v = next(u);
    if(v != -1) {
      if(color[v] == white) {
        color[v] = gray;
        d[v] = ++t;
        S.push(v);
      }
    }else {
      color[u] = black;
      f[u] = ++t;
      S.pop();
    }
  }

}

void dfs() {
  for(int i = 0;i < n;i++) {
    if(color[i] == white) dfs_visit(i);
  }

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



int main() {


cin >> n;

for(int i = 0;i < 100;i++) {
  for(int j = 0;j < 100;j++) {
    M[i][j] = 0;
  }
}

for(int i = 0;i < 100;i++) {
  color[i] = white;
  nt[i] = 0;
  d[i] = 0;
  f[i] = 0;
}

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

}

dfs();

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

int G[101][101];
bool visited[101];
int timex[101][2];
int now_time = 1;
int n;

void dfs(int node) {

	if (!visited[node]) {
		visited[node] = 1;
		timex[node][0] = now_time++;
		for (int i = 0; i < n; i++)	{
			if (G[node][i] && visited[i] == 0) {
				dfs(i);
			}
		}
		timex[node][1] = now_time++;
	}
}

void dfs_stack(int node) {

	stack<int> st;
	st.push(node);
	visited[node] = 1;
	timex[node][0] = now_time++;
	while (!st.empty()) {
		int ver = st.top();

		bool flag = false;
		for (int i = 0; i < n; i++)	{
			if (G[ver][i] && visited[i] == 0) {
				visited[i] = 1;
				timex[i][0] = now_time++;
				st.push(i);
				flag = true;
				break;
			}
		}
		if (!flag) {
			timex[ver][1] = now_time++;
			st.pop();
		}
	}

}


int main() {
	
	cin >> n;

	for (int i = 0; i < n; i++)	{
		int id, degree;
		cin >> id >> degree;
		for (int j = 0; j < degree; j++) {
			int idx; cin >> idx;
			G[id - 1][idx - 1] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (!visited[i])
			dfs_stack(i);
	}
	

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


	return 0;
}