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 <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

#define INF 1000000
vector<int> ds(100, INF);
vector<int> fs(100);
int t = 0;

vector<vector<int>> edges;
bool dfs(int now){
    if(ds[now] != INF)
        return false;
    t++;
    ds[now] = t;
    for(auto it = edges[now].begin(); it != edges[now].end();it++) {
        bool flag = dfs(*it);
        // t++;
    }
    // if(edges[now].size() == 0)
    t++;
    fs[now] = t;
    return true;
}

int check(int n) {
    rep(i, n) {
        if(ds[i] == INF)
            return i;
    }
    return -1;
}

int main(){
    int n; cin >> n;
    vector<int> tmp;
    rep(i, n) {
        edges.push_back(tmp);
        int id, num; cin >> id >> num;
        rep(j, num) {
            int dst; cin >> dst;
            dst--;
            edges[i].push_back(dst);
        }
        // sort(edges[i].rbegin(), edges[i].rend());
    }
    dfs(0);
    while(check(n) != -1) {
        dfs(check(n));
    }
    rep(i, n) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100

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

int nxt(int u){
	for (int v = nt[u]; v < n; ++v){
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}

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

	stack<int> s; s.push(idx);
	color[idx] = GRAY;
	d[idx] = ++t;

	while (!s.empty()) {
		int u = s.top();
		int v = nxt(u);
		if (-1 != v){
			if (WHITE == color[v]){
				color[v] = GRAY;
				d[v] = ++t;
				s.push(v);
			}
		}
		else{
			s.pop();
			color[u] = BLACK;
			f[u] = ++t;
		}
	}
}

void dfs(){
	for (int i = 0; i < n; ++i)	color[i] = WHITE;

	t = 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(){
	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){
		int u, d, v; cin >> u >> d;
		for (int j = 0; j < d; ++j)
		{
			cin >> v;
			M[u - 1][v - 1] = 1;
		}
	}

	dfs();
	return 0;
}

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

#define start first
#define end second

static const int NOT   = false;
static const int WHITE = 1;
static const int GRAY  = 2;
static const int BLACK = 3;
static const int N	   = 101;

int  n;
int  VisitedInfo[N];
bool Graph[N][N];
pair< int, int > Time[N];

void dfs( int u );
int  nextNode( int u );

int main()
{

	int u, k, v;

	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) Graph[i][j] = NOT;
		VisitedInfo[i] = WHITE;
	}

	scanf( "%d", &n );
	for( int i = 0; i < n; i++ ) {
		
		scanf( "%d %d", &u, &k );
		for( int j = 0; j < k; j++ ) {

			scanf( "%d", &v );
			Graph[u][v] = true;

		}

	}

	dfs( 1 );

	for( int i = 1; i <= n; i++ ) printf( "%d %d %d\n", i, Time[i].start, Time[i].end );

	return 0;

}

void dfs( int u )
{

	int  time = 1, pos, ppos;
	bool brkUpNodeFlg = false;
	stack< int > dfsInfo;

	dfsInfo.push( u );
	Time[u].start  = time;
	VisitedInfo[u] = BLACK;

	while( !dfsInfo.empty() ) {

		ppos = dfsInfo.top();

		if( !brkUpNodeFlg ) pos = nextNode( ppos );

		brkUpNodeFlg = false;

		if( pos != 0 ) {
			if( VisitedInfo[pos] == WHITE ) {

				dfsInfo.push( pos );
				Time[pos].start  = ++time;
				VisitedInfo[pos] = BLACK;

			}
		}
		if( pos == 0 && VisitedInfo[ppos] != WHITE ){

			dfsInfo.pop();
			Time[ppos].end	  = ++time;
			VisitedInfo[ppos] = BLACK;


		}

		if( dfsInfo.empty() ) {
			for( int i = 1; i <= n; i++ ) {
				if( VisitedInfo[i] == WHITE ) {

					pos = i;
					dfsInfo.push( pos );
					Time[pos].start  = ++time;
					VisitedInfo[pos] = BLACK;
					brkUpNodeFlg     = true;
					break;

				}
			}
		}

	}

}

int nextNode( int now )
{

	for( int i = 1; i <= n; i++ ) {
		if( Graph[now][i] && VisitedInfo[i] == WHITE ) return i;
	}

	return 0;

}

C++: #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

int dfs(int t, int v, vector<vector<int>> adj, vector<P>& ts) {
    if (ts[v].first != 0) return t;

    t++;
    ts[v].first = t;
    for (auto e : adj[v]) {
        t = dfs(t, e, adj, ts);
    }
    t++;
    ts[v].second = t;
    return t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    rep(i, n) {
        int u, k, v;
        cin>>u>>k; u--;
        rep(j, k) {
            cin>>v; v--;
            adj[u].push_back(v);
        }
    }

    vector<P> ts(n);
    int t = 0;
    rep(i, n) {
        if (ts[i].first != 0) continue;
        t = dfs(t, i, adj, ts);
    }
    rep(i, n) {
        cout<<i + 1<<" "<<ts[i].first<<" "<<ts[i].second<<endl;
    }
}