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<cstdio>
#define MAX_N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, u, k, v;
int adj[MAX_N][MAX_N];
int color[MAX_N], d[MAX_N], f[MAX_N], tt;

void dfs_visit(int num){
	color[num] = GRAY;
	d[num] = ++tt;
	for(int i = 0; i < n; i++){
		if(adj[num][i] == 0) continue;
		if(color[i] == WHITE){
			dfs_visit(i);
		}
	}
	color[num] = BLACK;
	f[num] = ++tt;
}

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

	for(int i = 0; i < n; i++){
		if(color[i] == WHITE){
			dfs_visit(i);
		}
	}
}

int main(void){
	scanf("%d", &n);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			adj[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		scanf("%d", &u);
		u -= 1;
		scanf("%d", &k);
		for(int j = 0; j < k; j++){
			scanf("%d", &v);
			v -= 1;
			adj[u][v] = 1;
		}
	}

	dfs();

	for(int i = 0; i < n; i++){
		printf("%d %d %d\n", i + 1, d[i], f[i]);
	}

	return 0;
}

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

using namespace std;

//4
//1 1 2
//2 1 4
//3 0
//4 1 3

//1 1 8
//2 2 7
//3 4 5
//4 3 6

const int MAX = 100;

int n;

int t = 0;

int G[MAX + 1][MAX + 1];
int d[MAX + 1];
int f[MAX + 1];

int color[MAX + 1];
int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

void dfs(int v) {
	color[v] = GRAY;
	d[v] = ++t;

	for (int i = 1; i <= n; ++i) {
		if (G[v][i] == 1 && color[i] == WHITE)
			dfs(i);
	}

	color[v] = BLACK;
	f[v] = ++t;
}

int main() {

	scanf("%d", &n);

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j)
			G[i][j] = 0;
	}

	for (int i = 1; i <= n; ++i) {
		int u, k;
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; ++j) {
			int v;
			scanf("%d", &v);
			G[i][v] = 1;
		}
	}

	for (int i = 1; i <= n; ++i) {
		if (color[i] == WHITE)
			dfs(i);
	}

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

	return 0;

}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class DirectedGraph
{
public:
    DirectedGraph()
    : t(1)
    {}
    DirectedGraph(int n)
    : t(1), g(vector< vs32 >(n)), d(vs32(n, 0)), f(vs32(n, 0))
    {}
    ~DirectedGraph() {}

    void dfs(int i)
    {
        d[i] = t++;
        rep (j, g[i].size())
        {
            if (d[g[i][j]] == 0)
            {
                dfs(g[i][j]);
            }
        }
        f[i] = t++;
    }

    int t;
    vector< vs32 > g;
    vs32 d;
    vs32 f;
};

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

    int n;
    cin >> n;

    DirectedGraph dg(n);
    int u, v;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        --u;
        dg.g[u].resize(c);
        rep (j, c)
        {
            cin >> v;
            --v;
            dg.g[u][j] = v;
        }
    }

    rep (i, n)
    {
        if (dg.d[i] == 0)
        {
            dg.dfs(i);
        }
    }

    rep (i, n)
    {
        cout << i + 1 << " " << dg.d[i] << " " << dg.f[i] << "\n";
    }
    return 0;
}

C++: 
#include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, i, count);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << i + 1 << " " << find[i] << " " << done[i] << endl;
	}

	return 0;
}