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;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define max 100005
#define nil -1

vector<vector<int>> g;
int t=0;
vector<int> d,f;
vector<bool> visited;

void dfs(int u){
    visited[u]=true;
    t++;
    d[u]=t;
    for(auto to:g[u]){
        if(!visited[to]){
            dfs(to);
        }
    }
    t++;
    f[u]=t;
}

int main() {
  int  n,u,k,v;
  cin>>n;
    g.resize(n);
    d.resize(n);
    f.resize(n);
    visited.resize(n, false);
  rep(i,n){
      cin>>u>>k;
      u--;
      for(int j=0;j<k;j++){
          cin>>v;
          v--;
          g[u].push_back(v);
        }
    }
    rep(i,n){
        if(!visited[i]){
            dfs(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
  return 0;
}

C++: #include<iostream>
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int M[N][N];
int color[N];
int d[N];
int f[N];
int tt;

//再帰関数によるDFS
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);
        }
    }

    //探索終了の記録
    //再帰初期のuほど遅く探索が終了する
    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++)
    {
        //未訪問のuを始点としてとしてDFS
        if(color[u]==WHITE) dfs_visit(u);
    }
    for(u=0;u<n;u++)
    {
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}


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

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<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u[200],k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
int Gcounter;
int Fcounter;
int Find;
void dfs(int where){
  fincou++;
  Fcounter++;
  //cout << "where " << where << " " << Find << endl; 
  GetIt[where]=Find;
  //cout << "GetIt[" << where << "] = " << GetIt[where] << endl;
 
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[imap[where][i]]){
	Gcounter++;
	Find++;

	used[imap[where][i]] = true;
	dfs(imap[where][i]);
	fincou++;
	Fcounter++;

      }
    }
  }
    FinIt[where] = fincou;
     
}
 
int main(){
  
  int ad;
   
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u[i];
    cin >> k[u[i]];
    for(int j=0;j<k[u[i]];j++){
      cin >> ad;
      imap[u[i]][j] = ad;
    }
  }
 
 
  for(int j=0;j<200;j++)used[j] = false;
  Gcounter=Fcounter=1;
 
  Find = 1;
  int Index=0;
  bool fin = true;
  fincou = 1;

  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	used[u[i]]=true;

      dfs(u[i]);
      Find = fincou+1;
      fincou++;      
      }
    }
  
  //dfs(u[0]);   

   
  
  //cout << "counter - " << Find << ", F" << fincou << endl;
  for(int i=0;i<n;i++){
    cout << u[i] << " " << GetIt[u[i]]  << " " << FinIt[u[i]];
    cout << endl;
  }
 
  return 0;
}

C++: #include<cstdio>
#include<queue>
#include<stack>
const int N = 101;
std::queue<int> Q[N];
void dfs(int root, int *tt, int d[], int f[]);
int main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int k;
        scanf("%d%d", &i, &k); //&i, so i--;
        for (int j = 0; j < k; j++) {
            int v; scanf("%d", &v);
            Q[i].push(v);//remember children
            //i starts from 1!. look scanf above
        }
        i--;
    }
    int d[N] = {0}, f[N] = {0}, tt = 0;
    for (int i = 1; i <= n; i++) if(!d[i]) dfs(i, &tt, d, f);//if cannot reach from 0
    for (int i = 1; i <= n; i++) printf("%d %d %d\n", i, d[i], f[i]);
    return 0;
}
void dfs(int root, int *tt, int d[], int f[]) {//from root search
    std::stack<int> S;
    S.push(root);
    d[root] = ++*tt;
    while (!S.empty() ) {
        int u = S.top();
        if (!Q[u].empty() ) {
            int v = Q[u].front();
            Q[u].pop();
            if (d[v] == 0) {
                d[v] = ++*tt;
                S.push(v);
            }
        } else {
            S.pop();
            f[u] = ++*tt;
        }
        
    }
}