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