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<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

void dfs_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){
            dfs_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) {
            dfs_visit(u);
        }
    }

    for(u = 0; u < n; u++){
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}


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

    dfs();
    return 0;

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

vector<int> g[105];
int d[105], f[105], visited[105];
int t = 1;

void dfs(int x){
    d[x] = t++;
    visited[x] = 1;
    for(int y: g[x]){
        if(visited[y] == 1) continue;
        dfs(y);
    }
    f[x] = t++;
}

int main(){
    int n;
    cin >> n;
    rep(i,n+1){
        d[i] = 0;
        f[i] = 0;
        visited[i] = 0;
    }
    rep(i,n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for(int i = 1; i <= n; i++){
        if (visited[i] == 0){
            dfs(i);
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int n;
int d[101], v[101];
int graph[101][101] = {};

int solve(int k, int cnt)
{
	d[k] = cnt;
	int nowcnt = cnt;
	for(int i = 0; i < n; i++){
		if(d[i] < 0 && graph[k][i] > 0) nowcnt = solve(i, nowcnt + 1);
	}
	return v[k] = nowcnt + 1;
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		d[i] = -1;
		v[i] = -1;
		int u, k;
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			v--;
			graph[u][v] = 1;
		}
	}
	solve(0, 1);
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << d[i] << " " << v[i] << endl;
	}
}

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

using namespace std;

long long inf=1000000007;
vector<bool> seen(10000,false);

void dfs(long long &cnt,long long now,vector<long long> &d,vector<long long> &f,vector<vector<long long>> kankei){
	seen.at(now)=true;
	cnt++;
	d.at(now)=cnt;

	for(auto a:kankei.at(now)){
		if(seen.at(a)) continue;

		dfs(cnt,a,d,f,kankei);
	}

	cnt++;
	f.at(now)=cnt;

	return;
}

int main(){
	long long n;
	cin>>n;
	vector<vector<long long>> kankei(n+1);

	for(long long i=1;i<=n;i++){
		long long k,u;
		cin>>k>>u;
		vector<long long> vec(u);
		for(long long j=0;j<u;j++){
			cin>>vec.at(j);
		}
		sort(vec.begin(),vec.end());

		kankei.at(k)=vec;
	}

	vector<long long> d(n+1,0);
	vector<long long> f(n+1,0);
	long long cnt=0;

	for(long long i=1;i<=n;i++){
		if(seen.at(i)) continue;

		dfs(cnt,i,d,f,kankei);
	}

	for(long long i=1;i<=n;i++){
		cout<<i<<" "<<d.at(i)<<" "<<f.at(i)<<endl;
	}

	return 0;
}

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

#define MAX_N 101

int counter;
int d[MAX_N];
int f[MAX_N];

void DFS(list<int>* G, int n){
	counter++;
	d[n] = counter;
	list<int>::iterator it;
	for(it=G[n].begin(); it!=G[n].end(); it++){
		if(d[*it-1]==0) DFS(G, *it-1);
	}
	counter++;
	f[n] = counter;
}

int main()
{
	counter = 0;
	for(int i=0; i<MAX_N; i++) d[i]=f[i]=0;
	int n;cin>>n;
	list<int> G[n];
	
	// input Graph data
	for(int i=0; i<n; i++){
		int u, k, v;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			cin >> v;
			G[u-1].push_back(v);
		}
	}
	// DFS
	for(int i=0; i<n; i++){
		if(d[i]==0){
			DFS(G, i);
		}
	}
	// Output Result
	for(int i=0; i<n; i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

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

int main(){
 int n,k,v,u;
  cin>>n;

  int V[100][100]; //隣接リスト
  int cnt[100];　//各点においてどこまでみたかの把握
  int d[100];
  int f[100];
  int time=1;
  int l=0;
  int come[100]; //その点はどこからきたかの把握

  //初期化
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      V[i][j]=0;
      cnt[j]=0;
      d[j]=0;
      f[j]=0;
      come[j]=0;
    }
  }
  //グラフ情報の読み込み
 int  m=0;
  for(int i=0;i<n;i++){
    cin>>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      V[u-1][m]=v;
      m++;
    }
    m=0;
  }


  //スタートは0
 d[0]=1;
 time++;
  while(1){

    if(time==2*n+1) break;
    //先がありかつそこは探索終了していない
    if(V[l][cnt[l]]!=0 && f[V[l][cnt[l]]-1]==0){ 
     
      if(d[V[l][cnt[l]]-1]==0) d[V[l][cnt[l]]-1]=time;

   come[V[l][cnt[l]]-1]=l;
      cnt[l]++;
      l=V[l][cnt[l]-1]-1; 

      time++;
      //先がないまたはさきが探索終了している
    }else{

      if(d[l]==0) d[l]=time;
       f[l]=time;
      l=come[l];
      time++;

    }

  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    cout<<V[i][j]<<" ";
    if(j==n-1) cout<<endl;
  }
  }
  */
  //出力
  for(int i=0;i<n;i++){

    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }


  return 0;
}