Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

int n, t, G[101][101], S[101], T[101];

void dfs(int p) {
    if (S[p] != 0) return;
    S[p] = ++t;
    for (int i = 0; i < n; i++)
        if (G[p][i] == 1)
            dfs(i);

    T[p] = ++t;
}


int main(void) {
    int u, k, v, s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u - 1][v - 1] = 1;
        }
    }

    t = 0;
    for (int i = 0; i < n; i++)
        dfs(i);

    for (int i = 0; i < n; i++)
        printf("%d %d %d\n", i + 1, S[i], T[i]);

    return 0;
}

C++: #include<iostream>

using namespace std;

int A[101][100];//データを入れる配列
int d[101];
int f[101];
int t = 1;//time

int Depth(int n){
    if((f[n] != 0)){//既に探索が終了していたら、その節点は飛ばす
        return 0;
    }
    if(d[n] == 0){//はじめて通る節点だったら、dに時間を記録
        d[n] = t;
        t++;
    }
    if((A[n][0] != 0)){//隣接点が1つ以上ある場合は以下のループに入る
        for(int i=1; i<=A[n][0]; i++){
            //if(A[n][i] == n){//自分自身に返ってくるノードだったら、
            //    f[A[n][i]] = t;
            //    t++;
            //    return 0;
            //}
            if((A[n][i] != n) && (d[A[n][i]] == 0)){
                Depth(A[n][i]);
            }
        }
    }
    f[n] = t;
    t++;
}

int main(){
    int n, num;
    cin >> n;
    for(int k=1; k<=n; k++){
        d[k] = 0;
        f[k] = 0;
    }
    for(int i=1; i<=n; i++){
        cin >> num;
        cin >> A[i][0];
        for(int j=1; j<=A[i][0]; j++){
            cin >> A[i][j];
        }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

int next(int u){//ntってなに？？現在地？
	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) {
	for ( int i =0; i<n;i++) nt[i] = 0;

	stack<int> S;
	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() {
	for (int i = 0; i<n;i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

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

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

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

	for (int i =0;i<n;i++){
		cin >> u >> k;
		u--;
		for ( int 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++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void dfs(int now, vector<vector<int>>& path, vector<int>& find, vector<int>& finish, int& time) {
		find[now] = time++;
		REP(i, path[now].size()) {
			int t = path[now][i];
			if (find[t] < 0) {
				dfs(t, path, find, finish, time);
			}
		}
		finish[now] = time++;
	}

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<vector<int>> path(n);
		REP(i, n) {
			int u, k;
			cin >> u >> k;
			u--;
			REP(j, k) {
				int v;
				cin >> v;
				v--;
				path[u].push_back(v);
			}
		}
		vector<int> visit(n, 0);
		vector<int> find(n, -1);
		vector<int> finish(n, -1);
		int time = 1;
		REP(i, n) {
			if (find[i] < 0) {
				dfs(i, path, find, finish, time);
			}
		}
		REP(i, n) {
			put(i + 1, find[i], finish[i]);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

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);
        }
    }
    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++){
        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;
}