Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <functional>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using pci = pair<char, int>;
using vpci = vector<pci>;
using vb = vector<bool>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(int i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) { ll prime; double sqrtmax = sqrt(max); vector<ll> primeVec, searchVec; FOR(i, 2, max + 1) searchVec.push_back(i); do { prime = searchVec[0]; primeVec.push_back(prime); auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; }); searchVec.erase(itr, searchVec.end()); } while (prime < sqrtmax); primeVec.reserve(primeVec.size() + searchVec.size()); primeVec.insert(primeVec.end(), beginend(searchVec)); return primeVec; }
bool isPrime(ll x) { if (x == 2) return true; if (x < 2 || x % 2 == 0) return false; ll i = 3; while (i <= sqrt(x)) { if (x%i == 0) return false; i += 2; }return true; }
vi seq(int max, int start = 0) {vi rt(max - start+1);FOR(i, start, max+1) rt[i] = i;return rt;}
template<typename T> size_t find_first_of(vector<T> v, T val) { auto itrfind = find(beginend(v), val); size_t dis = distance(v.begin(), itrfind); if (dis == v.size()) { return -1; }return dis; }
template<class T> struct Identity {typedef T type;};
template<typename T> vector<T> select(const vector<T> &v, typename Identity<function<T(const T &)>>::type ft) {vector<T> rt; for (T item : v) { rt.push_back(ft(item)); }return rt;}
template<typename T> string join(const vector<T> &v, typename Identity<function<string(const T &)>>::type ft) {string rt = "";Foreach(x, v) {rt += ft(x);}return rt;}

int d[105]{ 0 }, f[105]{ 0 };
int time = 1;
int N;
void dfs(vvi & box,int v) {
	if (d[v] != 0) return;
	d[v] = time++;
	for (int i = 0; i < N; i++) if (box[v][i] != 0) {
		dfs(box,i);
	}
	f[v] = time++;
	return;
}

int main(){
	cin >> N;
	vvi box(N, vector<int>(N, 0));
	REP(i, N) {
		int v, k, u;
		cin >> v >> k;
		REP(n, k) {
			cin >> u;
			box[i][u-1] = 1;
		}
	}
	dfs(box, 0);

	REP(i, N) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

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

void dfs_init();
void dfs(int u);

int n,**List,*deg,*d,*f;
bool **M;
string *color;
int vertex,time;

int main(){
	cin>>n;
	List = new int*[n]; M = new bool*[n]; deg = new int[n]; color = new string[n]; d = new int[n]; f = new int[n];
	for(int i=0;i<n;i++) List[i] = new int[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	for(int i=0;i<n;i++){
		List[i] = List[i]-1;
		M[i] = M[i]-1;
	}
	List = List-1; M = M-1; deg = deg-1; color = color-1; d = d-1; f = f-1;

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			M[i][j] = false;
		deg[i] = 0; d[i] = 0; f[i] = 0;
	}
	
	int k;
	for(int i=1;i<=n;i++){
		cin>>vertex>>k;
		for(int j=1;j<=k;j++){
			cin>>List[vertex][j];
			M[vertex][List[vertex][j]] = true;
		}
	}

	dfs_init();

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

	for(int i=1;i<=n;i++){
		delete [] (List[i]+1); delete [] (M[i]+1);
	}
	delete [] (List+1); delete [] (M+1);
	delete [] (deg+1); delete [] (color+1); delete [] (d+1); delete [] (f+1);
	cin.get(); cin.get();
}

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

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=1;v<=n;v++){
		if(M[u][v]==false) continue;
		if(color[v]=="WHITE"){
			dfs(v);
		}
	}
	color[u] = "BLACK";
	f[u] = ++time;
}