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 <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;

vector<int> V[105], color(105, 1), d(105), f(105);
int t = 0;

void func(int a) {
	t++;
	d[a] = t;
	color[a] = 2;
	Loop(i, V[a].size()) {
		if (color[V[a][i]] == 1) {
			func(V[a][i]);
		}
	}
	t++;
	f[a] = t;
	color[a] = 3;
}

int main() {
	int n;
	cin >> n;
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(j, k) {
			int v;
			cin >> v;
			V[u].push_back(v);
		}
	}
	func(1);
	Loop1(i, n) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

static const int DFS_VISIT_NO   = 0;
static const int DFS_VISIT_NOW  = 1;
static const int DFS_VISIT_DONE = 2;

static int g_time = 0;
static int g_setime[100][2] = {0};

void DfsVisit(int graph[][100], int num, int node, int state[])
{
    int i;

    ++g_time;
    g_setime[node][0] = g_time;

    state[node] = DFS_VISIT_NOW;

    for (i = 0; i < num; i++) {
        if ((graph[node][i] == 1) && (state[i] != DFS_VISIT_DONE)) {
            DfsVisit(graph, num, i, state);
        }
    }

    state[node] = DFS_VISIT_DONE;

    ++g_time;
    g_setime[node][1] = g_time;

    return;
}


void DFS(int graph[][100], int num)
{
    int i;
    int state[100];

    for (i = 0; i < num; i++) {
        state[i] = DFS_VISIT_NO;
    }

    for (i = 0; i < num; i++) {
        if (state[i] == DFS_VISIT_NO) {
            DfsVisit(graph, num, i, state);
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int target, tnum, node;
    int num;
    int graph[100][100] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d" "%d", &target, &tnum);
        --target;
        for (j = 0; j < tnum; j++) {
            scanf("%d", &node);
            --node;
            graph[target][node] = 1;
        }
    }

    DFS(graph, num);
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

int n;
int graph[MAX][MAX];
stack<int> st;
int *d,*f,*v;
int *color;

int next(int k){
	for(int i = v[k];i < n;i++){
		v[k]++;
		if(color[i] == WHITE && graph[k][i] == 1) return i;
	}
	return -1;
}

void dfs(int k){
	for(int i = 0;i < n;i++) v[i] = 0;
	int time = 0;

	st.push(k);
	d[k] = ++time;
	color[k] = GRAY;

	while(!st.empty()){
		int m = next(st.top());
		if(m != -1){
		  if(color[m] == WHITE){
				st.push(m);
				color[m] = GRAY;
				d[m] = ++time;
			}
		}else{
			f[st.top()] = ++time;
			color[st.top()] = BLACK;
			st.pop();
		}
	}
	for(int i = 0;i < n;i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main(){
	cin >> n;
	//?????????
	color = new int[n];
	d = new int[n];
	f = new int[n];
	v = new int[n];
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		d[i] = 0;
		f[i] = 0;
		for(int j = 0;j < n;j++){
			graph[i][j] = 0;
		}
	}
	//data input
	for(int i = 0;i < n;i++){

		int t,k,p;

		cin >> t >>  k;
		for(int j = 0;j < k;j++){
			cin >> p;
			p--;
			graph[i][p] = 1;
		}
	}
	dfs(0);
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;

void InputSet(std::vector<int> & a) {
	int n;
	cin >> n;
	a.resize(n,0);
	for(int i=0;i<n;++i) {
		cin >> a.at(i);
		a.at(i)--;
	}
}
void DFS(vector<vector<int> > & Ad,
		 vector<int> & D,
		 vector<int> & F,
		 int & time,
		 int idx)
{
	if (F[idx] < 0) {
		for(int i=0;i<(int)Ad[idx].size();++i) {
			int next = Ad[idx][i];
			if (D[next] < 0) {
				D[next] = time++;
				DFS(Ad,D,F,time,next);
			}
		}
		F[idx]= time++;
	}
}
int main(){
	int n;
	cin >> n;
	vector<vector<int> > Ad(n);
	vector<int> D(n,-1),F(n,-1);
	for(int k=0;k<n;++k) {
		int u;
		cin >> u;
		--u;
		InputSet(Ad[u]);
	}
	int time=1;
	D[0] = time++;
	DFS(Ad,D,F,time,0);
	for(int i=0;i<n;++i){
		cout << i + 1 << " " << D[i] << " " << F[i] << endl;
	}
}