Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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