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+1)
	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++: #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;
}