Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <bits/stdc++.h>

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != 2) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int n;
vector<vector<int>> to, timestamp;

void dfs(int v, int& t) {
    timestamp[v][0] = t++;
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (timestamp[nv][0] > 0) continue;
        dfs(nv, t);
    }
    timestamp[v][1] = t++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    to.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            to[u].push_back(v);
        }
    }

    timestamp.resize(n, vector<int>(2, 0));
    int t = 1;
    rep(i, n) {
        if (timestamp[i][0] == 0) dfs(i, t);
    }

    rep(i, n) {
        cout << i+1 << " " << timestamp[i][0] << " " << timestamp[i][1] << endl;
    }
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int count = 1;
std::vector<vector<int> > G;
std::vector<int> flag;
std::vector<int> in;
std::vector<int> out;
int N;
int dfs(int u, int count) {
	flag[u] = 1;
	
	in[u] = count;
	for (int i = 0; i < N; ++i) {
		if (flag[i] == 0 && G[u][i] == 1) {
			count = dfs(i, count + 1);
		}
	}
	out[u] = count + 1;
	return count + 1;
}

int main(int argc, char const *argv[]) {
	
	cin >> N;

	for (int i = 0; i < N; ++i) {
		G.push_back(vector<int>());
		flag.push_back(0);
		in.push_back(0);
		out.push_back(0);
		for (int j = 0; j < N; ++j) {
			G[i].push_back(0);
		}
	}

	for (int i = 0; i < N; ++i) {
		int u, k;
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; ++j) {
			int v;
			cin >> v;
			v--;
			G[u][v] = 1;
		}
	}

	dfs(0, 1);

	for (int i = 0; i < N; ++i) {
		cout << i + 1 << " " << in[i] << " " << out[i] << endl;
	}

	return 0;
}

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

int Stime = 0;
vector<int> edges[100];
bool visit[100];
int be[100]; //begin
int en[100]; //end


void dfs(int cur) //curを訪問
{
	//curの訪問時間を記録
	Stime++;
	visit[cur] = true;

	//cout << "visiting " << cur+1 << "  time:" << time << endl;
	be[cur] = Stime;

	for (int i = 0; i < edges[cur].size(); ++i)
	{
		if (!visit[edges[cur][i]])
		{
			dfs(edges[cur][i]);
		}
	}

	Stime++;

	//cout << "finished visiting " << cur+1 << "  time:" << time << endl;
	en[cur] = Stime;

}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 100; ++i)
	{
		visit[i] = false;
	}

	int u,k,v;
	for (int i = 0; i < n; ++i)
	{
		cin >> u >> k;

		for (int j = 0; j < k; ++j)
		{
			cin >> v;
			edges[i].push_back(v-1);
		}
	}

	int temp = 0;
	int flag = true; //未探索のノードがあるかどうか
	while(flag)
	{
		dfs(temp);
		flag = false;
		for (int i = 0; i < n; ++i)
		{
			if (!visit[i])
			{
				temp = i;
				flag = true;
				break;
			}
		}
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i+1 << " " << be[i] << " " << en[i] << endl;
	}
	return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

#define white 0
#define gray 1

int M[110][110];
vector<int> color(110,white),d(110),f(110);
int t=0;
int n;

void dfs(int u){
  color[u]=gray;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v] && color[v]==white) dfs(v);
  }
  f[u]=++t;
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=0;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    x--;
    rep(j,y){
      cin>>z;
      z--;
      M[x][z]=1;
    }
  }

  rep(i,n){
    if(color[i]==white) dfs(i);
  }
  
  rep(i,n) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  
  return 0;
}