Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}


}

C++: #include<iostream>
#include<stack>
using namespace std;
#define White 0
#define Black 1
#define Red 2
#define MAX 100
struct Queue {
	int color, d, f, relate[MAX], roots, id;
};
Queue Q[MAX];
stack<int> q;
stack<int> dmax;
int search(int deep) {
	while (!q.empty()) {
		int s = q.top();
		int whitecount = 0;
		for (int i = 0; i < Q[s - 1].roots; i++) {
			int nakami = Q[s - 1].relate[i];
			if (Q[nakami - 1].color == White) {
				whitecount += 1;
				deep += 1;
				Q[nakami - 1].color = Black;
				q.push(Q[nakami - 1].id);
				Q[nakami - 1].d = deep;
				search(deep);
			}
		}
		if (whitecount == 0) {
			deep += 1;
			Q[s - 1].f = deep;
			dmax.push(deep);
			Q[s - 1].color = Red;
			q.pop();
			search(deep);
		}
	}
	return dmax.top();
}
int main() {
	int n, u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		Q[i].color = White;
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		Q[u - 1].id = u;
		Q[u - 1].roots = k;
		if (i == 0) {
			Q[u - 1].d = 1;
			Q[u - 1].color = Black;
			q.push(u);
		}
		if (k != 0) {
			for (int i = 0; i < k; i++) {
				cin >> v;
				Q[u - 1].relate[i] = v;
			}
		}
	}
	int max = search(1);
	for (int i = 0; i < n; i++) {
		if (Q[i].color == White) {
			Q[i].d = max + 1;
			q.push(Q[i].id);
			search(max+1);
			max = search(max);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << Q[i].id << " " << Q[i].d << " " << Q[i].f << endl;
	}

}

C++: #include<stdio.h>
#define N 100
#define WHITE 0 // ????¨??????????????????????????????°
#define GRAY 1 // ??¢?´¢?????????????????????????????°
#define BLACK 2 // ??¢?´¢????????????????????????????????°

int n,/* ????????° */ M[N][N]; /* ??£??\?????? */
int color[N],/* ??????i????¨??????¶??? */ d[N],/* ??????i?????????????¨?????????????????????? */ f[N],/* ??????i?????£??\??????????????????????????????????????? */ 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; // ??????u????????????v????????????????????¨?????????
		if(color[v] == WHITE){
			dfs_visit(v); // ??????v????¨???????????????¨??????????????°???v??????????????¢?´¢???????§???????
		}
	}
	color[u] = BLACK; // ??¢?´¢??????????????????BLACK?????°????????????
	f[u] = ++tt; // ????????????
}

void dfs(){
	int u;
	// ?????????
	for(u=0;u<n;u++) color[u] = WHITE;
	tt = 0;

	for(u=0;u<n;u++){
		// ????¨???????u????§??????¨????????±???????????¢?´¢
		if(color[u] == WHITE) 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; // u:??????????????? k:u???????¬???° v:??£??\?????????????????????

	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>

using namespace std;

typedef pair<int, int> p;

int n,u,k,t;
int** v;
p* T;

void bfs(int pos) {
  // if visited
  if (T[pos].first) {
    return;
  }
  // check visit
  T[pos].first = ++t;

  int leng = v[pos][0];
  for (int i = 1; i <= leng; i++) {
    bfs(v[pos][i]);
  }
  T[pos].second = ++t;
}

int main() {
  cin >> n;

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

  T = new p[n+1];
  for (int i = 1; i <= n; i++) {
    T[i] = p(0, 0);
  }

  t = 0;
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }

  for (int i = 1; i <= n; i++) {
    cout << i << " " << T[i].first << " " << T[i].second << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int White=0;
static const int Gray=1;
static const int Black=2;

int M[N][N];
int d[N],nt[N],f[N],tt,color[N];
int n;
int next_v(int k){
  for(int i=nt[k];i<=n;i++){
    nt[k]=i+1;
    if(M[k][i]) return i;
  }
  return -1;
}
void dfs_visit(int r){
  stack<int> S;
  S.push(r);
  color[r]=Gray;
  d[r]=++tt;

  while(!S.empty()){
    int u=S.top();
    int v=next_v(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(){
  tt=0;
  for(int i=1;i<=n;i++){
    if(color[i]== White)dfs_visit(i);
  }
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k,v;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      M[u][v]=1;
    }
  }
  dfs();
}