Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;


struct Edge{ //??°????????????
public:
    int src, dst;
    int weight;
    Edge(int a,int b):src(a),dst(b),weight(1){} //?????????????????????
    void setWeight(double x){
        weight = x;
    }
};
typedef vector<Edge> Edges; //???????????£??\?????????
typedef vector<Edges> Graph; //??°???????????£??\???????????¨???

typedef vector<int> Array; //??´??°?????????
typedef vector<Array> Matrix; //??´??°???????????£??\?????????

const int N = 100;
const int White = 0, Gray = 1, Black =2;

int n;
int tt = 0;
Matrix M(N,Array(N,0));
vector<int> d(N,0), f(N,0);
vector<int> color(N,0);


vector<int> nt(N,0);//???????????????????????????????????§?????????????¨???¶??????

int next(int u){ //???u?????\?¶??????????????????????????????????
    if (nt[u]!= n) {
        for(int i = nt[u];i<n;i++){
            if(M[u][i]){
                nt[u] = i+1;
                return i;
            }
        }
        return -1;
    } else {
        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 v = S.top();
        int w = next(v);
        if (w != -1) {
            if (color[w]==White) {
                color[w] = Gray;
                d[w] = ++tt;
                S.push(w);
            }
        } else {
            S.pop();
            color[v] = Black;
            f[v] = ++tt;
        }
    }
    
}

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


int main(){
    
    int k,v,w;
    
    cin >> n; //??°????????????????????\???
    
    for (int i=0; i<n; i++) { //??????????¬???°?????????????????\??? ???????????\??????????????£??\??????????????£??\?????????????´?
        cin >> w >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            M[w-1][v-1] = 1; //?????????
        }
    }
    
    dfs();
    
    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int N     = 100;
int       white = 0;
int       gray  = 1;
int       black = 2;

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

// 再帰による深さ優先探索
void dfs_visit(int u) {
    color[u] = gray;
    d[u]     = ++tt;  //最初の訪問
    rep(v, n) {
        if (m[u][v] == 0) continue;
        if (color[v] == white) {
            dfs_visit(v);
        }
    }
    color[u] = black;
    f[u]     = ++tt;  // 訪問の完了
}

void dfs() {
    //初期化
    rep(u, n) color[u] = white;
    tt                 = 0;
    rep(u, n) {
        // 未訪問のuを始点として深さ優先探索
        if (color[u] == white) dfs_visit(u);
    }
    rep(u, n) { cout << u + 1 << " " << d[u] << " " << f[u] << endl; }
}

// 再帰による深さ優先探索
int main() {
    int u, v, k;
    cin >> n;
    rep(i, n) rep(j, n) m[i][j] = 0;

    rep(i, n) {
        cin >> u >> k;
        u--;
        rep(j, k) {
            cin >> v;
            v--;
            m[u][v] = 1;
        }
    }
    dfs();

    return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[100]={0}, p=1;

void dfs(int n){
    if(visit[n]!=1){
        visit[n] = 1;
        d[n] = p++;
        for(int i=1; i<num+1; i++)
            if(r[n][i]==1) dfs(i);
        f[n] = p++;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]=1;
        }
    }
    for(int i=1; i<num+1; i++){
        if(visit[i]!=1) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];
 
int times = 1;
int n;
int graph[101][101];
 
void bfs(int now){
 
  T[now].f = true;
  T[now].begin = times++;
 
  for( int i = 1 ; i <= n; i++ ){
    if( graph[now][i] == 1 && !T[i].f ) bfs(i);
  }
  T[now].end = times++;
 
}
 
int main(void){
 
  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  for( int i = 1 ; i <= n ; i++ ){
    if( !T[i].f ) bfs(i);
  }
 
  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }
 
 
  return 0;
}