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 <iostream>
#include <stack>
using namespace std;

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

int d[101], f[101];
int color[101] = { 0 };
int M[101][101] = { 0 };

int times;

int cur;

stack<int> s;

int search_node(int n) {
    for (int node = 1; node <= n; ++node) {
        if (M[cur][node] == 1 && color[node] == WHITE) {
            return node;
        }
    }
    return -1;      // 見つからなかった場合
}

void visit_node(int target) {
    times += 1;
    s.push(target);
    cur = s.top();
    d[cur] = times;
    color[cur] = GRAY;
}

void reversal_node() {
    // ノードを戻っていく終了時刻を記入する処理+スタック削除
    times += 1;
    s.pop();
    f[cur] = times;
    color[cur] = BLACK;
    if (s.size() != 0) {
        cur = s.top();
    } else {
        cur = 0;
    }
}

bool black_judge(int n) {        // すべて探索済みか判定，初期化
    for (int node = 1; node <= n; ++node) {
        if (color[node] != BLACK) {
            s.push(node);
            cur = node;
            color[node] = GRAY;
            d[node] = times;
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int u, k;
    int ver;
    times = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> u >> k;
        for (int j = 1; j <= k; ++j) {
            cin >> ver;
            M[i][ver] = 1;           // 隣接行列が得られる
        }
    }

    while (true) {
        times += 1;
        if (black_judge(n)) {
            break;                  // すべて探索済みなら完了
        }
        while (s.size() != 0) {
            int target;
            target = search_node(n);
            if (target == -1) {
                reversal_node();
            } else {
                visit_node(target);
            }
        }
    }
    
    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,k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
void dfs(int where,int find){
  fincou++;  
 
  GetIt[where]=find;
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[where]){
	dfs(imap[where][i],find+1);
	fincou++;
	used[where] = true;
      }
    }
  }
    FinIt[where] = fincou;
    
}

int main(){
 
  int ad;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u;
    cin >> k[u];
    for(int j=0;j<k[u];j++){
      cin >> ad;
      arisutoteresu[u][ad] = 1;
      imap[u][j] = ad; 
    }
  }


  for(int j=0;j<n;j++)used[j] = false;
  dfs(1,1);

  for(int i=0;i<n;i++){
    cout << i+1 << " " << GetIt[i+1]  << " " << FinIt[i+1];
    cout << endl;
  }

  return 0;
}

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

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
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;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r)
{
    int i;
    stack<int> S;

    for (i = 0; i < n; i++) nt[i] = 0;

    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int v = next(u);

        if (v != -1) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs()
{
    int i, u;

    // 初期化
    for (i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    tt = 0;

    // 未訪問の u を始点として深さ優先探索
    for (u = 0; u < n; u++) {
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main()
{
    int u, k, v;
    int i, j;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++) M[i][j] = 0;
    }

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

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

vector<int> grid[105];
vector<bool> seen(105, false);
P ans[105];
int t = 0;

void dps(int now)
{
    seen[now] = true;
    ++t;
    ans[now].first = t;
    for (int next : grid[now])
    {
        if (seen[next])
        {
            continue;
        }
        dps(next);
    }
    ++t;
    ans[now].second = t;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            grid[u].push_back(v);
        }
    }
    for (int i = 1; i < n; i++)
    {
        if (!seen[i])
        {
            dps(i);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << ' ' << ans[i].first << ' ' << ans[i].second << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}