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>
#define N 101
using namespace std;

int n,d[N][N],m[N],f[N],s[N],ti;
void dfs(int t){
  if(s[t]==1) return;
  ti++,m[t]+=ti,s[t]=1;
  for(int i=1;i<=n;i++) if(d[t][i]==1 && s[i]==0)dfs(i);
  ti++,f[t]+=ti;
}

int main(){
  int nx,s,fst;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>fst>>nx;
    for(int j=0;j<nx;j++){
      cin>>s;
      d[fst][s]=1;
    }
  }
  for(int i=1;i<=n;i++) dfs(i);
  for(int i=1;i<=n;i++) cout<<i<<" "<<m[i]<<" "<<f[i]<<endl;
  
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

int timestamp = 1;

void search(int index, vector<vector<int> > &graph, vector<int> &dest, vector<int> &fin) {
    if (dest[index - 1] != -1) return;
    dest[index - 1] = timestamp;
    timestamp++;
    for (int& dsts: graph[index - 1]) {
        search(dsts, graph, dest, fin);
    }
    fin[index - 1] = timestamp;
    timestamp++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n, vector<int>());

    rep(i, n) {
        int index, k;
        cin >> index >> k;
        rep(j, k) {
            int dst;
            cin >> dst;
            graph[index - 1].push_back(dst);
        }
    }

    
    vector<int> dest(n, -1);
    vector<int> fin(n, -1);

    rep(i, n) {
        search(i + 1, graph, dest, fin);
    }

    rep(i, n) {
        cout << i+1 << " " << dest[i] << " " << fin[i] << endl;
    }
}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}


}

C++: #include<iostream>
#include<stack>
using namespace std;
#define White 0
#define Black 1
#define Red 2
#define MAX 100
struct Queue {
	int color, d, f, relate[MAX], roots, id;
};
Queue Q[MAX];
stack<int> q;
stack<int> dmax;
int search(int deep) {
	while (!q.empty()) {
		int s = q.top();
		int whitecount = 0;
		for (int i = 0; i < Q[s - 1].roots; i++) {
			int nakami = Q[s - 1].relate[i];
			if (Q[nakami - 1].color == White) {
				whitecount += 1;
				deep += 1;
				Q[nakami - 1].color = Black;
				q.push(Q[nakami - 1].id);
				Q[nakami - 1].d = deep;
				search(deep);
			}
		}
		if (whitecount == 0) {
			deep += 1;
			Q[s - 1].f = deep;
			dmax.push(deep);
			Q[s - 1].color = Red;
			q.pop();
			search(deep);
		}
	}
	return dmax.top();
}
int main() {
	int n, u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		Q[i].color = White;
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		Q[u - 1].id = u;
		Q[u - 1].roots = k;
		if (i == 0) {
			Q[u - 1].d = 1;
			Q[u - 1].color = Black;
			q.push(u);
		}
		if (k != 0) {
			for (int i = 0; i < k; i++) {
				cin >> v;
				Q[u - 1].relate[i] = v;
			}
		}
	}
	int max = search(1);
	for (int i = 0; i < n; i++) {
		if (Q[i].color == White) {
			Q[i].d = max + 1;
			q.push(Q[i].id);
			search(max+1);
			max = search(max);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << Q[i].id << " " << Q[i].d << " " << Q[i].f << endl;
	}

}