Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: // J4180449 三宅亮輔
// 問題名
// - Depth First Search
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_11_B
// 所要時間
// - 35分
// 学んだこと
//  どこで時間を更新するのかの理解に苦しんだ
//  番号が小さい順に巡ることをソートで実装しようとしたが必要ないと気づいて楽になった
//  再帰関数のスマートさに感動した

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

typedef long long ll;

int n;

vector<int> v[100];
bool visited[100];
int d[100];
int f[100];

int dfs(int i, int now) {
    visited[i] = true;
    now++;
    d[i] = now;
    for(int j = 0; j < v[i].size(); j++) {
        if(!visited[v[i][j]])
            now = dfs(v[i][j], now);
    }
    now++;
    f[i] = now;
    return now;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            v[u].push_back(x);
        }
    }
    int now = 0;
    for(int i = 0; i < n; i++) {
        if(!visited[i])
            now = dfs(i, now);
    }

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

C++: #include<iostream>
using namespace std;
int N,t=0;
int d[101][101],Ts[101],Te[101];
bool visit[101];
void graph(){
    int u,k,a;
    for(int i=1;i<=N;++i){
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>a;
            d[u][a]=1;
        }
        visit[i]=true;
    }
}
void dfs(int cur){
    t+=1;
    Ts[cur]=t;
    visit[cur]=false;
    for(int i=1;i<=N;++i){
        if(d[cur][i]==1&&visit[i]){
            visit[i]=false;
            dfs(i);
         }
    }
    t+=1;
    Te[cur]=t;
}
int main(){
    cin>>N;
    graph();
    dfs(1);
    for(int i=1;i<=N;++i){
        cout<<i<<" "<<Ts[i]<<" "<<Te[i]<<endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
#include <stack>

using namespace std;

#define INF 2e9 + 9
#define ALL(v) v.begin(), v.end()
#define Int int64_t
#define pll pair<Int, Int>
template <class T>
using pql = priority_queue<T, vector<T>>;
template <class T>
using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) \
    Int n;    \
    cin >> n;
#define LL(...)       \
    Int __VA_ARGS___; \
    cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for (Int i = s; i < n; i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) \
    if (maxer < updater)        \
        maxer = updater;

vector<vector<Int>> to;
vector<Int> d;
vector<Int> f;
/*
Int dfs(Int from, Int time){
    if (d[from] != 0) return 0;
    Int maxer = time;
    d[from] = time;
    Int cnt = 0;
    for (auto next : to.at(from)){
        maxer= max(dfs(next,maxer+1),maxer);
    }
    if (maxer == 0) return f[from] = d[from];
    return f[from] = maxer+1;
}*/


/*
    stackの挿入ルール
    未探索だと思って追加する時はpairの2つめの値を0とする
    既探索だけど、完了時刻を確認するためにstackに追加する時は-1とする
    -1ならnowtimeを追加、nowtime++して次へ飛ばす
    違ったら、自分が本当に未探索かどうかを判断した上で、未探索であれば
    自分の発見時刻をメモ、次に探索する所を追加して、ターン終了
*/
Int dfs(Int x, Int t){
    Int nowtime = t;
    stack<pll> st;
    st.push({x,0});
    while(!st.empty()){
        //stackから取り出してきて
        auto z = st.top();
        Int from = z.first;
        Int op = z.second;
        st.pop();

        if (op == -1) { // 完了時刻の記入
            f[from] = nowtime;
            nowtime++;
        }

        if (d[from] != 0) continue;

        //ここから未探索確定
        st.push({from,-1});
        d[from] = nowtime;
        nowtime++;
        for (int i = to[from].size() - 1; i >= 0; i--){//次探索する箇所は、未探索だと思って挿入
            st.push({to[from][i],0});
        }
    }
    return nowtime;
}



int main() {
    Int n;
    cin >> n;
    to.resize(n);
    d.resize(n);
    f.resize(n);

    REP(n,i){
        Int u, k;
        cin >> u >> k;
        REP(k,kk) {
            Int x;
            cin >> x;
            x--;
            to.at(i).push_back(x);
        }
    }
    
    Int time = 1;
    
    REP(n,i){
        if (d[i] == 0){
            //time = dfs(i,time) + 1;
            time = dfs(i,time);
        }
    }  

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

}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    cout << node << endl;
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << start[i] << " " << finish[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<vector<int>> G;
vector<bool> seen;
vector<pair<int,int>> ts;
int cnt=1;

void dfs(int v){
    seen[v]=true;
    ts[v].first = cnt;
    cnt++;

    for(auto next_v : G[v]){
        if(seen[next_v])continue;
        dfs(next_v);
    }
    ts[v].second = cnt;
    cnt++;
}

int main(){
    int N; 
    cin>>N;
    G.resize(N);
    ts.resize(N);
    rep(i,N){
        int u,k; 
        cin>>u>>k;
        rep(j,k){
            int vz; 
            cin>>vz;
            G[u-1].push_back(vz-1);
        }
    }
    seen.assign(N, false);
    for(int i=0; i<N; i++){
        if(!seen[i])dfs(i);
    }
    rep(i,N){
        cout<<i+1<<" "<<ts[i].first<<" "<<ts[i].second<<endl;
    }
    return 0;
}