Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int n = 0;
int u = 0;
int k[101];
int v[101][101];
int Discover[101] = { 0 };
int End[101] = { 0 };
//int nx = 0;
int p = 0;
void dfs(int l) {
	int i;
	int j;
	if (!Discover[l]) {
		Discover[l] = ++p;

		for (i = 0; i < n + 1; i++) {
			if (v[l][i]) {
				dfs(v[l][i]);
			}
		}
		End[l] = ++p;
	}
}
int main()
{
	int i;
	int j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u ;
		cin >> k[u];
		for (j = 0; j < k[u]; j++) {
			cin >> v[u][j];
		}
	}
	for (i = 1; i < n + 1; i++) {
		if (!Discover[i]) {
			dfs(i);
		}
	}
	for (i = 1; i < n + 1; i++) {
		cout << i << " " << Discover[i] << " " << End[i] << endl;
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

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

// u?????£??\??????v?????????????????????
int next(int u){
    for (int v = nt[u]; v < n ; v++) {
        nt[u] = v +1;
        if(M[u][v]) return v;
    }
    return -1;
}

//with stack

void dfs_visit (int r){
    for (int i = 0; i < n ; ++i) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    tt ++; 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(){
    int u;
    for (u = 0; u < n; ++u) {
        color[u] = white;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == white) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int u,v,k;
    M[N][N] = {0};
    cin >> n;
    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>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vector< vector<int> > graph(110, vector<int>());
vector<int> fst(110, -1);
vector<int> snd(110, -1);

int abstime = 0;
void dfs(int now) {
    // cout << "ok" << endl;
    if(fst.at(now) != -1) return;
    abstime++;
    fst.at(now) = abstime;
    for(int i = 0; i < graph.at(now).size(); ++i) {
        dfs(graph.at(now).at(i));
    }
    abstime++;
    snd.at(now) = abstime;
}

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 v;
            cin >> v;
            v--;
            graph.at(u).push_back(v);
        }
    }

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

    for(int i = 0; i < n; ++i) {
        cout << i+1 << " " << fst.at(i) << " " << snd.at(i) << endl;
    }
}

C++: #include<iostream>
#include<vector>

using namespace std;

int N;
vector<vector<int>> tree;
vector<pair<int,int>> times;

void stamp(int ind, int &time){
	//cout << ind << "," << time << endl;
	if(times[ind].first == 0) times[ind].first = time++;
	else return;
	if(tree[ind].size() == 0){
		times[ind].second = time++;
		//cout<<"break! " << ind << endl;
		return;
	}
	for(int i=0;i<tree[ind].size();i++){
		//cout << tree[ind][i] << endl;
		stamp(tree[ind][i],time);
	}
	//cout << ind << ":" << time << endl;
	times[ind].second = time++;
}

int main(){
	cin >> N;
	tree = vector<vector<int>>(N+1);
	times = vector<pair<int,int>>(N+1,make_pair(0,0));

	for(int i=1;i<N+1;i++){
		int ind, branch;
		cin >> ind >> branch;
		vector<int> tmp(branch);
		for(int j=0;j<branch;j++){
			int in;
			cin >> in;
			tmp[j] =  in;
		}
		tree[ind] = tmp;
	}

	int time = 1;
	stamp(1,time);

	int i = 1;
	for(auto st:times){
		if(i<=N)
			cout << i << " " << times[i].first << " " << times[i].second << endl;
		i++;
	}

	return 0;
}

C++: /*16D8103008D 西村悠輝　nissy0507barista  alds11_B*/ 

#include<iostream>

#define MAX 100
using namespace std;

int n,v,k,u; ///超点数、頂点番号、出次数、隣接
int d[MAX], f[MAX];///タイムスタンプ
int a[MAX][MAX];
int cnt=0;
int flag[MAX]; ///通ったかどうか

void dfs(int x) {

	if (flag[x] == 1)return;
	cnt++;
	d[x] += cnt;
	flag[x] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[x][i] == 1 && flag[i] == 0) dfs(i);
	}
	cnt++;
	f[x] += cnt;

}

int main(void)
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v >> k;
		for (int j = 0; j < k; j++) {
			cin >> u ;
			a[v][u]=1;
		}
	}
	
	for (int i = 1; i <= n; i++) dfs(i);

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

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
stack<int> s;
int n;
int m[N][N];
int used[N];
int time = 1;
int bb_start[N];
int bb_end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1 && used[i] == 0) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    bb_start[root] = time++;

    while(!s.empty()) s.pop();
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            bb_start[v] = time++;
            s.push(v);
        } else{
            bb_end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    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++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, bb_start[i], bb_end[i]);
    }
    return 0;
}