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 <vector>
using namespace std;

vector<int> G[100];
pair<int, int> T[100];
const int Inf = 10000*100000+100;
int timer = 1;

int main() {
  void dfs(int cur);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int l = 0; l < k; l++) {
      int v;
      cin >> v;
      G[i].push_back(v - 1);
    }
    T[i] = make_pair(Inf, Inf);
  }
  for (int i = 0; i < n; i++) {
    if (T[i].first == Inf) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << T[i].first << " " << T[i].second << endl;
  }
}

void dfs(int cur) { // cur を訪問
  // cur の訪問時刻を記録
  T[cur].first = timer;
  timer += 1;
  // 動作確認用表示
  for (int dst : G[cur]) { // 全ての節点 dst について
    if (T[dst].first == Inf)
    { // cur から dst に辺があり，dst を未訪問なら
      dfs(dst);
    }
  }
  T[cur].second = timer;
  timer += 1;
}

C++: #include <cstdio>

typedef struct timestamp {
        int d, f;
} timestamp;

const int N = 100;
bool graph[N][N];
timestamp ts[N];
int time = 0;

void search(int n, int cur) {
        if (ts[cur].d) {
                return;
        }
        ts[cur].d = ++time;
        for (int i = 0; i < n; i++) {
                if (graph[cur][i]) {
                        search(n, i);
                }
        }
        ts[cur].f = ++time;
}

int main() {
        int n, u, k, v;
        for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                        graph[i][j] = false;
                }
        }
        for (int i = 0; i < N; i++) {
                ts[i].d = ts[i].f = 0;
        }

        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                scanf("%d %d", &u, &k);
                if (!k) {
                        continue;
                }
                for (int j = 0; j < k; j++) {
                        scanf("%d", &v);
                        graph[u-1][v-1] = true;
                }
        }
        int cur = 0;
        search(n, cur);
        for (int i = 0; i < n; i++) {
                printf("%d %d %d\n", i+1, ts[i].d, ts[i].f);
        }

        return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int a[100],d[100],f[100];
int inf=100000,t=0,n;
int v[100][100];
void dfs(int s){
    d[s]=t++;
    a[s]=inf;
    for(int i=0;i<n;i++){
        if(v[s][i]==1&&a[i]!=inf){
            //cout<<s<<" "<<i<<endl;
            dfs(i);
        }
    }
    f[s]=t++;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int tmp;
      cin>>tmp;
      v[u-1][tmp-1]=1;
    }
  }
  dfs(0);
  for(int i=0;i<n;i++)
      if(!a[i])dfs(i);
  for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]+1<<" "<<f[i]+1<<endl;
  }
}

C++: #define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 100
//#define MAX_ 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = 0, f = 0;
};
Graph G[MAX];
int cou = 1;
void Depth(Graph *g)
{
	if (g->k >= 0) {
		if (g->d)
			return; 
		
		g->d = cou;
		++cou;
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			Depth(&G[*i]);
		}
		g->f = cou;
		++cou;
		
	}
}

int main(void)
{
	int n, u, xk, v;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &u, &xk);
		G[u - 1].id = u - 1;
		G[u - 1].k = xk;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &v);
			G[u - 1].node.push_back(v - 1);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (G[i].d == 0 && G[i].f == 0) 
			Depth(&G[i]);
		
	}
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", G[i].id + 1, G[i].d, G[i].f);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

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

//u に隣接するvを番号順に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if( M[u][v] ) return v; 
    }
    return NIL;
}

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

    while(S.size() != 0){
        int u = S.top();
        int v = next(u);
        if(v != NIL){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

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

    //未訪問のuを始点として深さ優先探索
    for(int u = 0; 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(){
    cin >> n;
    int u, k, v;

    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++){
        scanf("%d %d", &u, &k);
        for(int j = 0; j < k; j++){
            scanf("%d", &v);
            M[u-1][v-1] = 1;
        }
    }

    dfs_init();

    return 0;
}