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;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
//------------------------------------------------------------------------------------------------------------------------------
vector<vector<int>> G;
vector<int> d, f;
int t;
void dfs(int v) {
    d[v] = ++t;
    for(auto nv : G[v]){
        if(d[nv]>0){
            continue;
        }
        dfs(nv);
    }
    f[v] = ++t;
}

int main(void) { 
    int N;
    cin >> N;
    G.resize(N);
    d.resize(N);
    f.resize(N);
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int i = 0; i < k; i++) {
            int v;
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    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] << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int common_time=1,n;

int table[101][101],time_table[101][2];

void func(int node){
	if(time_table[node][0] == 0){
		time_table[node][0] = common_time++;
	}else{
		return;
	}
	for(int i=1;i<=n;i++){
		if(table[node][i] == 1){
			func(i);
		}
	}
	time_table[node][1] = common_time++;
}

int main(){
	int row,num,col;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			table[i][k]=0;
		}
		time_table[i][0]=0;
		time_table[i][1]=0;
	}

	for(int i=1;i<=n;i++){
		scanf("%d %d",&row,&num);
		for(int k=1;k<=num;k++){
			scanf("%d",&col);
			table[row][col]=1;
		}
	}

	for(int i=1;i<=n;i++){
		func(i);
	}

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

    return 0;
}

C++: #include<iostream>

int main(){

  int n,a;
  std::cin>>n;

  int Adj[100][100],adj[100][100]={0},find[100][2],back[100],depth[100]={0},endflag[100]={0},flag;
  int u[n],k[n],kcou=0,timenow=0,v,pred,prev;
  for(int i=0;i<n;i++){
    std::cin>>u[i];
    std::cin>>k[i];
    for(int j=0;j<k[i];j++){
      std::cin>>Adj[i][j];
    }
  }
	
	/*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    	std::cout<<Adj[i][j]<<" ";
    }
  	std::cout<<"\n";
  }*/
	
	v=0;

	while(timenow<n*2){
		flag=0;
		//std::cout<<find[v][0]<<" "<<find[v][1];
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(endflag[v]==1){
				timenow++;
				find[v][1]=timenow;
				flag=2;
			}
			//std::cout<<flag<<" 2";
		}else{
			v=back[v];
			flag=3;
			//std::cout<<flag<<" 0";
		}

		if(flag==0){
			pred=depth[v];
			depth[v]++;
			prev=v;
			v=Adj[v][pred]-1;
			back[v]=prev;
			//std::cout<<flag<<"\n";
		}else if(flag==1){
			if(endflag[v]==1){
				depth[v]++;
			}else{
				pred=depth[v];
				depth[v]++;
				prev=v;
				v=Adj[v][pred]-1;
				back[v]=prev;
				//std::cout<<v<<"\n";
			}
		}else if(flag==2){
			v=back[v];
			//std::cout<<flag<<"\n";
		}
		if(depth[v]>k[v]-1){
			endflag[v]=1;
		}
		
	}
	
	
	
	
  for(int i=0;i<n;i++){
     std::cout<<i+1<<" "<<find[i][0]<<" ";
     std::cout<<find[i][1]<<"\n";
    //std::cout<<"\n";
  }

  return 0;
}

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

const int SIZE = 100;
int Adj[SIZE][SIZE+3];
int d[SIZE];
int f[SIZE];
int t=0;

void DFS(int id){
    
    //t++;

    // タイムスタンプが押されている
    if (d[id-1] != 0){
        return;
    }

    d[id-1] = ++t;

    for(int i=2;Adj[id-1][i]!=0;i++){
        DFS(Adj[id-1][i]);
    }

    f[id-1] = ++t;
}

int main(){
    int n;
    cin >> n;
    
    // 初期化
    for(int i=0;i<SIZE;i++){
        d[i] = 0;
        f[i] = 0;
        for(int j=0;j<SIZE+3;j++){
            Adj[i][j] = 0;
        }
    }

    // 入力受付
    for(int i=0;i<n;i++){
        cin >> Adj[i][0] >> Adj[i][1];
        for(int j=0;j<Adj[i][1];j++){
            cin >> Adj[i][j+2];
        }
    }

    for(int i=1;i<=n;i++){
        if(d[i-1]!=0){
            continue;
        }
        DFS(i);
    }

    // 出力
    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " <<f[i] << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<P> ans;
vector<vector<int>> e;

int dfs(int nn, int time) {
    // 探れるところがあるか探す
    if (ans[nn].first == 0) {
        // 到達していなければ時間を足して記録
        time += 1;
        ans[nn].first = time;
        // cout << "achived " << nn << ": " << time << endl; 
    }
    rep(i, e[nn].size()) {
        if (ans[e[nn][i]].first != 0) continue;
        // 到達していない箇所があれば入る
        time = dfs(e[nn][i], time);
    }
    time += 1;
    ans[nn].second = time;
    return time;
}

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    // vector<vector<int>> e(n);
    e.resize(n);
    rep(i, n) {
        int id; cin >> id; id--;
        int k; cin >> k;
        rep(j, k) {
            int v; cin >> v; v--;
            e[id].emplace_back(v);
        }
    }

    // vector<P> ans(n);
    ans.resize(n);
    int time = 0;
    rep(i, n) {
        if (ans[i].first == 0) {
            time = dfs(i, time);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}