Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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

int n;
int g[101][101];
char c[101];
int visit[101];
int finish[101];
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[u][v] = 1;
        }

    }

   stack<int> s;
    for (int l = 1; l <= n; ++l) {
        c[l] = 'w';

    }
    int time = 0;
    int start = 0;
    int v;
    while(true) {
        start++;
        if(start == n) break;
        if(c[start] == 'w') {
            time++;
            s.push(start);
            c[start] = 'g';
            visit[start] = 1;
            while (s.size() != 0) {
                time++;
                v = s.top();
                int next = -1;
                for (int i = 1; i <= n ; ++i) {
                    if(i == v) {
                        continue;
                    }
                    if(g[v][i] && c[i] == 'w') {
                        next = i;
                        break;
                    }
                }
                if(next == -1) {
                    c[v] = 'b';
                    finish[v] = time;
                    s.pop();
                } else {
                    c[next] = 'g';
                    visit[next] = time;
                    s.push(next);
                }
            }
        }
    }

    for (int m = 1; m <= n; ++m) {
        cout << m << " " << visit[m ] << " " << finish[m] << endl;

    }



    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t) {
    visited[s] = true;
    ans[s].first = t;
    REP(i, g[s].size()) {
        if (visited[g[s][i]]) continue;
        t = dfs(g[s][i], t + 1);
    }
    t++;
    ans[s].second = t;
    return t;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        int u, m;
        cin >> u >> m;
        REP(j, m) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1, T = 0; i <= n; i++) {
        if (visited[i]) continue;
        T = dfs(i, T+1);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

C++: // ALDS1_12_A: Depth First Search
#include <iostream>
#include <vector>
#include <algorithm>
bool debug = false;

std::vector<std::pair<int,int>> runtime_memo;
std::vector<int> vertex_stat;
std::vector<std::vector<int>> adjacency_list;
int runtime = 0;

void init() {
    int total; std::cin >> total;
    /* Resize containers */
    runtime_memo.resize(total);
    vertex_stat.resize(total);
    adjacency_list.resize(total);
    for (int i=0;i<adjacency_list.size(); i++) {
        adjacency_list.at(i).resize(total);
    }
    for (int i=0; i<adjacency_list.size(); i++) {
        for (int j=0; j<adjacency_list.at(i).size(); j++) {
            adjacency_list.at(i).at(j) = 0;
        }
    }

    /* Set adjacency_list */
    int vertex, outdegree;
    for (int i=0; i<adjacency_list.size(); i++) {
        std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int tmp; std::cin >> tmp;
            adjacency_list.at(vertex-1).at(tmp-1) = 1;
        }
    }
}

void DepthFirstSearch(int vertex) {
    int tmp_vertex = vertex -1;
    vertex_stat.at(tmp_vertex) = 1;
    runtime++;
    runtime_memo.at(tmp_vertex).first = runtime;
    for (int i=0; i<adjacency_list.at(tmp_vertex).size(); i++) {
        if (adjacency_list.at(tmp_vertex).at(i) == 1) {
            if (vertex_stat.at(i) == 0) {
                if (debug) std::cout << "DepthFirstSearch(" << i+1 << ")" << "\n";
                DepthFirstSearch(i+1);
            }
        }
    }
    vertex_stat.at(tmp_vertex) = 2;
    runtime++;
    runtime_memo.at(tmp_vertex).second = runtime;
}

int main() {
    /* Initialization */
    init();
    /* Depth first search */
    for (int i=0; i<vertex_stat.size(); i++) {
        int id = i+1;
        if (vertex_stat.at(i) == 0) {
            DepthFirstSearch(id);
        }
    }
    /* Output */
    for (int i=0; i<adjacency_list.size(); i++) {
        int id = i+1;
        std::cout << id << " ";
        std::cout << runtime_memo.at(i).first << " ";
        std::cout << runtime_memo.at(i).second << "\n";
    }
}