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 <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)

const int MAX_N = 100;
int n, t = 0, flag[MAX_N] = {0}, d[MAX_N], f[MAX_N], G[MAX_N][MAX_N] = {0};

void dfs(int u) {
  int v;
  flag[u] = 1;
  d[u] = ++t;
  REP(v, n) {
    if (!G[u][v]) continue;
    if (!flag[v]) dfs(v);
  }
  flag[u] = 2;
  f[u] = ++t;
}

int main() {
  int u, v, k;
  cin >> n;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      G[u - 1][v - 1] = 1;
    }
  }
  REP(i, n) if (!flag[i]) dfs(i);
  REP(i, n) cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
  return 0;
}

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

struct time_check {
    int find_time, end_time;
};

int main() {
    int G[101][101] = {0};
    time_check t[101];

    for (int i = 1; i <= 100; i++) t[i].end_time = 0;

    stack<int> S;
    int n, u, v, k, elapsed=1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }
    S.push(1);
    t[1].find_time = 1;
    while (! S.empty()) {
        elapsed++;
        u = S.top();
        for (int i = 1; i <= n + 1; i++) {
            if (G[u][i] == 1 && t[i].end_time == 0) {
                t[i].find_time = elapsed;
                G[u][i] = 0;
                S.push(i);
                break;
            }
            if (i == n + 1) {
                t[u].end_time = elapsed;
                S.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << t[i].find_time << " " << t[i].end_time << endl;
    }

    return 0;
}
このコードはWrong Answerです...
理由は以下のコードのl.111のとこのように未訪問の頂点を始点としてdfsしてないから
*/

#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BRACK = 2;

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 -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] = BRACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    // 初期化
    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() {
    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<bits/stdc++.h>
using namespace std;

int adj[101][101],d[101],f[101], n;

int step;
void dfs(int start){
	stack<int> S;
	S.push(start);

	++step;
	d[start]=step;

	while(S.size()){
		int u=S.top();

		int v=0;
		for(int i=1;i<=n;i++){
			if(adj[u][i]==1 && d[i]==0){
				v=i;	break;
			}
		}

		++step;
		if(v==0){
			f[u]=step;
			S.pop();
		}else{
			d[v]=step;
			S.push(v);
		}
	}
}

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 v;	cin>>v;
			adj[u][v]=1;
		}
	}

	step=0;
	for(int i=1;i<=n;i++){
		if(d[i]==0)dfs(i);
	}

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

	return 0;
}

C++: /**
 * Depth first search.
 * start from node 1
 * 1) increment time 
 * 2) find non visited adjacent node
 * 3) if found move to that node.  d[v'] = time
 * 4) if not found. f[v] = time
 * 5) else end.
 * 5) go to 2.
 */

#include <iostream>
using namespace std;
const int N = 101;
int adj[N][N] = {0};
int d[N]={0};
int f[N]={0};
int t = 1;

void dfs(int n) {
	d[n]=t;
	int k = adj[n][0];
	for (int j=1;j<=k;j++) {
		int nn = adj[n][j];
		if (d[nn]) continue;
		t++;
		dfs(nn);
	}
	f[n]=++t;
}

int main()
{
	int n;
	cin >> n;
	for (int i=1;i<=n;i++){
		int j, k;
		cin >> j >> k;
		adj[j][0]=k;
		for (int m=1;m<=k;m++) {
			int a;
			cin >> a;
			adj[j][m]=a;
		}
	}
	dfs(1);

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

	return 0;
}

C++: #include<stdio.h>
#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 visit(int);
void dfs(void);

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;
}

void 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]==WHITE){
      visit(v);
    }
  }
  color[u]=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++){
    if(color[u]==WHITE)visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int time = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	time++;
	a[t].t = time;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	time++;
	a[t].e = time;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}