Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include <iostream>

using namespace std;

int Time=0,d[101],f[101],v[101][101];
void Init()
{
    int i;
    for(i=1;i<=100;i++)
        d[i]=0;
}
void dfs(int cur,int n)
{
    int i;
    Time += 1;
    d[cur]=Time;
    for(i=1;i<=n;i++)
    {
        if(v[cur][i]==1 && d[i]==0)
            dfs(i,n);
    }
    Time += 1;
    f[cur] = Time;
}
int Find(int n,int d[])
{
    int flag=0,i;
    for(i=1;i<=n;i++)
        if(d[i]==0)
        {
            flag=i;
            break;
        }
    return flag;
}
int main()
{
    int n,m,k,i,j,flag;
    cin >> n;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            v[i][j]=0;
    for(i=1;i<=n;i++)
    {
        cin >> i >> k;
        for(j=1;j<=k;j++)
        {
            cin >> m;
            v[i][m]=1;
        }
    }
    Init();
    dfs(1,n);
    while(1)
    {
        flag = Find(n,d);
        if(flag == 0)
            break;
        else    dfs(flag,n);
    }
    for(i=1;i<=n;i++)
    {
        cout << i << ' ' << d[i] << ' ' << f[i] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> g(n, vector<int>());
    int u, k;
    REP(i, n) {
        cin >> u >> k;
        u--;
        int v;
        REP(j, k) {
            cin >> v;
            v--;
            g[u].emplace_back(v);
        }
    }

    vector<int> d(n, 0);
    vector<int> f(n, 0);
    int count = 0;
    function<void(int)> dfs = [&](int c) {
        if (d[c] == 0) d[c] = count;
        for (auto t : g[c]) {
            if (d[t] != 0) continue;
            count++;
            dfs(t);
        }
        count++;
        f[c] = count;
    };
    REP(i, n) if (d[i] == 0) {
        count++;
        dfs(i);
    }

    REP(i, n) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
int _time = 0;
stack<int> route;
void dfs(int root, vector<vector<bool>> &conn_mat, vector<bool> &accessed, vector<pair<int, int>> &result)
{
	accessed[root] = true;
	result[root].first = _time;
	int index;
	bool end = true;
	for (index = 0; index < conn_mat.size(); index++)
	{
		if (conn_mat[root][index] == true && accessed[index] == false)
		{
			_time++;
			result[index].first = _time;
			dfs(index, conn_mat, accessed, result);
			end = false;
		}
	}
	if (end)
	{
		_time++;
		result[root].second = _time;
		return;
	}
	_time++;
	result[root].second = _time;
	return;
}

int main()
{

	int n_node, index, n_cn, cn;
	cin >> n_node;
	vector<bool> vertex(n_node, false);
	vector<vector<bool>> conn_mat(n_node, vertex);
	vector<bool> &accessed = vertex;
	vector<pair<int, int>> result(n_node, make_pair(1, 0));
	while (n_node--)
	{
		cin >> index >> n_cn;
		while (n_cn--)
		{
			cin >> cn;
			conn_mat[index - 1][cn - 1] = true;
		}
	}
	bool end = false;
	while (!end) {
		_time++;
		int i = 0;
		while (accessed[i]) {
			i++;
		}
		dfs(i, conn_mat, accessed, result);
		end = true;
		for (auto acc : accessed) {
			end = end && acc;
		}
	}
	int i = 1;
	for (auto out : result) {
		cout << i << ' ' << out.first << ' ' << out.second << endl;
		i++;
	}
	return 0;
}

C++: /**
 * Depth first search.
 * start from node 1
 * 1) increment time 
 * 2) find non visited adjacent node
 * 3) if found move to that node.  d[v'] = time
 * 4) if not found. f[v] = time
 * 5) else end.
 * 5) go to 2.
 */

#include <iostream>
using namespace std;
const int N = 101;
int adj[N][N] = {0};
int d[N]={0};
int f[N]={0};
int t = 1;

void dfs(int n) {
	if (d[n]) return;
	d[n]=++t;
	int k = adj[n][0];
	for (int j=1;j<=k;j++) {
		dfs(adj[n][j]);
	}
	f[n]=++t;
}

int main()
{
	int n;
	cin >> n;
	for (int i=1;i<=n;i++){
		int j, k;
		cin >> j >> k;
		adj[j][0]=k;
		for (int m=1;m<=k;m++) {
			int a;
			cin >> a;
			adj[j][m]=a;
		}
	}

	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 <vector>
using namespace std;

void dfs(int cur, vector<vector<int> > arr, int d[], int f[], int &time, int n, bool psd[]){
    d[cur] = time;
    time++;
    psd[cur] = true;
    for(int dst = 0; dst < n; dst++){
        if(arr[cur][dst] == 1 && !psd[dst]){
            dfs(dst,arr,d,f,time,n,psd);
        }
    }
    f[cur] = time;
    time++;
}

int main(){
    int n;
    scanf("%d",&n);
    vector<vector<int> > arr(n,vector<int>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            arr[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        int u,k;
        scanf("%d %d",&u,&k);
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d",&v);
            arr[u-1][v-1] = 1;
        }
    }
    int d[n],f[n],time = 1;
    bool psd[n];
    for(int i = 0; i < n; i++){
        psd[i] = false;
    }
    for(int cur = 0; cur < n; cur++){
        if(!psd[cur]){
            dfs(cur,arr,d,f,time,n,psd);
        }
    }
    for(int id = 0; id < n; id++){
        printf("%d %d %d\n", id+1, d[id], f[id]);
    }
}