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>
#include <vector>

using namespace std;

#define MAX_N (105)

vector<int> G[MAX_N];
bool arrived[MAX_N];
int d[MAX_N];
int f[MAX_N];
int n;
int t;
void dfs( int cur ) {
    t++;
    d[cur] = t;

    for ( int i = 0; i < G[cur].size(); i++ ) {
	int next = G[cur][i];
	if ( !arrived[next] ) {
	    arrived[next] = true;
	    dfs( next );
	}
    }

    t++;
    f[cur] = t;

    return;
}

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

    t = 0;
    dfs(0);

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

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	if (book[u] == white) return; 
	else
		if (book[u] == black)
		{
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
				dfs(*it-1);
			book[u] = white;
			t[u][1] = ++tot;
		}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u,k,v;
		scanf("%d%d", &u,&k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for(int i=0;i<n;i++)
		if(book[i]==black)
	       dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d", i + 1, t[i][0], t[i][1]);
		if (i != n - 1)printf("\n");
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
static const int N = 100;

int n;
int M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] == 1 && color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_print() {
	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);
		}
	}

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

int main() {
	cin >> n;
	int u, k;
	int index;

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

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> index;
			M[u - 1][index - 1] = 1;
		}
	}
	dfs_print();
}

C++: #include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

#define NMAX 100
#define NIL -1

int d[NMAX + 1];           // start time, 1-origin
int f[NMAX + 1];           // finish time, 1-origin
stack<int> S;              // visited but not finished
vector<int> adj[NMAX + 1]; // adj
int n = 0;
int cnt = 0;

int next_unvisited_adj(int u) { // next not visited adj of u
    for (vector<int>::iterator it = adj[u].begin(); it != adj[u].end(); it++) {
        if (d[*it] == 0) // not finished
            return *it;
    }
    return NIL;
}

int next_unvisited() {
    for (int i = 1; i <= n; i++) {
        if (d[i] == 0)
            return i;
    }
    return NIL;
}

void dfs() {
    int x; // start vertex
    while ((x = next_unvisited()) != NIL) {
        // printf("dfs component of %d\n", x);
        S.push(x);
        d[x] = ++cnt;
        while (!S.empty()) { // dfs this component
            // check if the last visited guy is finished
            // if yes, pop it from the stack
            // if no, push the next unfinished adj of it
            int u = S.top();
            // printf("u=%d\n", u);
            int v = next_unvisited_adj(u);
            if (v != NIL) {
                if (d[v] == 0) { // v is not visited
                    // printf("%d is found\n", v);
                    d[v] = ++cnt;
                    S.push(v);
                }
            } else { // u is finished
                // printf("%d is finished\n", u);
                S.pop();
                f[u] = ++cnt;
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        d[i] = 0; // not visited
        f[i] = 0; // not finished
    }
    for (int i = 0; i < n; i++) {
        int u, k, v;
        scanf("%d", &u);
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            adj[u].push_back(v);
        }
    }
    dfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}