Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include "stdafx.h"

#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<bits/stdc++.h>
#include<string.h>
#define MAX 101
#define WHITE -1
#define GRAY 2
#define BLACK 1
using namespace std;

int G[MAX][MAX]={},d[MAX]={},f[MAX]={},color[MAX]={},times=0,Adj[MAX]={};

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

void visit(int u,int n){
    color[u]=GRAY;
    d[u]=++times;
    int v=1;
    while(v<=n){
        if(G[u][v]>0){
            if(color[v]==WHITE)visit(v,n);
        }
        v++;
    }
    color[u]=BLACK;
    f[u]=++times;
}

void dfs(int V[],int n){
    int u;
    for(u=1;u<=n;u++){
        color[u]=WHITE;
    }
    times =0;
    for(u=1;u<=n;u++){
        if(color[u]==WHITE)visit(u,n);
    }
}

int main(){
  int n,i,k,j,A,B,V[MAX]={};
  cin>>n;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
        G[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    cin>>A>>k;
    for(j=0;j<k;j++){
      cin>>B;
      G[A][B]=1;
    }
  }
  dfs(V,n);
  print(n);
}