Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<bits/stdc++.h>
using namespace std;
void func(int p);
int n;
int box[101][101];
int d[101];
int f[101];
int flg[101];
int t;
int main(void){
	int u,k,v;
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			box[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			box[u][v]=1;
		}
	}
	t=0;
	for(i=1;i<=n;i++){
		if(!flg[i]){
			func(i);
		}
	}
	for(i=1;i<=n;i++)	cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}
void func(int p){
	int i;
	t++;
	d[p]=t;
	flg[p]=true;
	for(i=1;i<=n;i++){
		if(box[p][i]==1){
			if(!flg[i]){
				func(i);
			}
		}
	}
	t++;
	f[p]=t;
}

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

int g[101][101], d[101], f[101];

int dfs(int id, int t)
{
    if(d[id]) return t;
    d[id]=++t;
    int n=g[id][0];
    for(int i=1; i<=n; i++) {
        t=dfs(g[id][i], t);
    }
    f[id]=++t;
    return t;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, k;
        cin>>id>>k;
        g[id][0]=k;
        for(int j=1; j<=k; j++) {
            cin>>g[id][j];
        }
    }
    dfs(1, 0);
    for(int i=1; i<=n; i++) {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}

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

using namespace std;

int d[10010]={0};//最初に訪問した時刻を入れるタイムスタンプ
int f[10010]={0};//vの隣接リストを調べ終えた時刻のタイムスタンプ

int back[10010]={0};//番号nのもときた街番号をいれる

int g[1001][1001]={{0}};//要素を0で初期化
int timestamp = 1;
int number;
int dfs(int cur){
  timestamp += 1;
  for(int dst = 0; dst < number; dst++){
    if(g[cur][dst]==1 && d[dst]==0){
      d[dst]=timestamp;
      back[dst]=cur;
      dfs(dst);
    }
  }
  // timestamp += 1;
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  if(timestamp > number*2){
    return 0;
  }
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  f[cur]=timestamp;
  dfs(back[cur]);
}
void ans(int n){
  for (int i = 0; i < n; ++i)
  {
    cout << i+1 << " " << d[i] <<" "<< f[i] <<endl;
  }
}

int main(){
  // int g[1001][1001]={{0}};//要素を0で初期化
  int n,a,b,c;
  cin >> n;
  number = n;
  for (int i = 0; i < n; ++i)
  {
    cin >> a >> b ;
    for (int i = 0; i < b; ++i)
    {
      cin >> c;
      g[a-1][c-1]=1;/* code */
    }
  }
  d[0]=1;
  dfs(0);
  for (int i = 0; i < number; ++i)
  {
    if(d[i]==0){
      dfs(i);
    }
  }
  // for (int i = 0; i < number; ++i)
  // {
  //   cout << back[i]<<" ";
  // }

  ans(n);
}

C++: /*
    Problem 24
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 102;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
vector<int> d(MAX), f(MAX), deg(MAX), cur(MAX);
int t = 1;
/* function */
void dfs(int st) {
    stack<int> S;
    S.push(st);
    d[st] = t++;
    while (!S.empty()) {
        int from = S.top();
        if (cur[from] >= deg[from]) {
            f[from] = t++;
            S.pop();
            continue;
        }
        int to = G[from][cur[from]++];
        if (d[to] != 0) continue;
        d[to] = t++;
        S.push(to);
    }
}
/* main */
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v;
        cin >> u >> k;
        u--;
        deg[u] = k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }

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

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

C++: #include <iostream>
#include <stack>
#include <vector>

using namespace std;

static const int N = 100; // 1 <= n <= 100
static const int WHITE = 0; // 未訪問は0
static const int GRAY = 1; // 訪問中は1
static const int BLACK = 2; // 訪問完了は2

int n; // 頂点数n
vector<vector<int>> M(N, vector<int>(N,0)); // M[u][v]：uからvに出ているか否か
vector<int> color(N), d(N), f(N); // d(i)：頂点i発見時刻，f(i)：頂点i完了時刻
int tt; // 経過時間tt
vector<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;
}

// 地点rについてスタックを用いた深さ優先探索
void dfs_visit(int r) {
    //初期化
    for ( int i = 0; i < n; i++ ){
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    
    tt++;
    d[r] = tt;
    
    while ( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if ( v != -1 ) {
            if ( color[v] == WHITE ) {
                color[v] = GRAY;
                tt++;
                d[r] = tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            tt++;
            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++){
        cin >> u >> k;
        u--;
        for(int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
        
        dfs();
        return 0;
    }
}