Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <iostream>
#include <string>

// 深さ優先探索
// Depth First Search(DFS)
// 可能な限り隣接する頂点を訪問する

using namespace std;

const int N_MAX = 100;

enum ColorStatus
{
    WHITE_no_visit,
    GRAY_visit,
    BLACK_finished,
};

struct Node
{
   ColorStatus color;
   // 最初の訪問時刻
   int discoverTime;
   // 訪問完了時刻
   int finishTime;
};

int n; // 頂点数
int M[N_MAX][N_MAX] = { 0 };
Node nodes[N_MAX] = { WHITE_no_visit, 0, 0 };
int times = 0;

// 引数の頂点uを始点にして、深さ探索
// 頂点u->頂点v
void depthFirstSearch(int u)
{
    int v;

    nodes[u].color = GRAY_visit; // 頂点uに訪れた
    nodes[u].discoverTime = ++times; // 訪問時刻のタイムスタンプ
    // 行先頂点v
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0) continue;
        if (nodes[v].color == WHITE_no_visit)
            depthFirstSearch(v);
    }
    nodes[u].color= BLACK_finished; // 頂点uを訪問し終えた。
    nodes[u].finishTime = ++times;
}

void init()
{
    for (int u = 0; u < n; u++)
        if (nodes[u].color == WHITE_no_visit)
            depthFirstSearch(u);

    // 出力
    // 頂点番号 発見時刻 完了時刻
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << nodes[u].discoverTime << " " << nodes[u].finishTime << endl;
    }

}



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u;
        int k;
        cin >> u; // 頂点番号
        cin >> k; // 出自数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    init();


    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int d[111], f[111];
bool visited[111];
vector<vector<int> > g(111);
int t;
void dfs(int x){
  t++;
  d[x] = t;
  visited[x] = true;
  for(auto &u : g[x]){
    if(!visited[u]){
      dfs(u);
    }
  }
  t++;
  f[x] = t;
}

int main(){
  int n; cin >> n;
  FOR(i,0,n){
    int u, k; cin >> u >> k;
    FOR(j,0,k){
      int v;
      cin >> v;
      g[u].push_back(v);
    }
  }
  FOR(i,0,n+1) visited[i] = false;
  t = 0;
  FOR(i,1,n+1){
    if(!visited[i]) dfs(i);
  }

  FOR(i,1,n+1){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	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].push_back(tmp);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			G[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			G[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
}
}

C++: #include <stdio.h>
#define MAX_N (105)

int n;
int G[MAX_N + 1][MAX_N + 1];
int d[MAX_N + 1];		// ????????????
int f[MAX_N + 1];		// ????????????
int time;
int dfs(int cur)
{
    d[cur] = time;
    for ( int i = 1; i <= n; i++ ) {
	if ( G[cur][i] && (d[i] == 0)) {
	    time++;
	    dfs(i);
	}
    }
    time++;
    f[cur] = time;
}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    G[u][v] = 1;
	}
    }

    time = 1;

    dfs(1);

    for ( int i = 1; i <= n; i++ ) {
	printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

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 = -1;
        for (int j = 0; j < n; ++j){
            if(M[u][j] == 1 && color[j] == WHITE) {
                v = j;
                break;
            }
        }
        if (v != -1){
            S.push(v);
            color[v] = GRAY;
            d[v] = ++tt;
        } else {
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

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

    for( u = 0; u < n; ++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;
    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;
}