Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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]);
    }
}

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

class Adjl{
private:
	int u;
	int k;
	Adjl **next;
protected:
	int d;
	int f;
public:
	Adjl(int u);
	~Adjl(){ if (next != NULL) delete[] next; }
	void setV(int k, Adjl *vk);
	int depthFirstSearch(int time);
	void print();
};

Adjl::Adjl(int u)
{
	this->u = u;
	k = 0;
	next = NULL;
	d = 0;
	f = 0;
}

void Adjl::setV(int k, Adjl *vk)
{
	if (this->k == 0) next = new Adjl*[k];
	next[this->k] = vk;
	(this->k)++;
}

int Adjl::depthFirstSearch(int time)
{
	time++;
	d = time;
	for (int i = 0; i < k; i++) {
		if (next[i]->d == 0) {
			time = next[i]->depthFirstSearch(time);
		}
	}
	time++;
	f = time;
	return time;
}

void Adjl::print()
{
	cout << u << " " << d << " " << f << endl;
}

int main(void)
{
	int n;
	cin >> n;
	
	Adjl **adjl = new Adjl*[n];
	int check[100] = {0};

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		if (check[i] == 0) {
			adjl[i] = new Adjl(u);
			check[i] = 1;
		}
		check[i] = 1;
		for (int j = 0; j < k; j++) {
			int vk;
			cin >> vk;
			if (check[vk - 1] == 0) {
				adjl[vk - 1] = new Adjl(vk);
				check[vk - 1] = 1;
			}
			adjl[i]->setV(k, adjl[vk - 1]);
		}
	}

	adjl[0]->depthFirstSearch(0);

	for (int i = 0; i < n; i++) {
		adjl[i]->print();
	}

	delete[] adjl;
	return 0;
}