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
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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<iostream>
#include<vector>
using namespace std;
vector<vector<int>> G(100);
vector<pair<int,int>> D(100);
bool visited[100];
int elapse = 1;
void dfs(int x){
    if(visited[x]) return;
    visited[x] = true;
    D[x].first = elapse;
    elapse++;
    for(auto &a:G[x]) dfs(a);
    D[x].second = elapse;
    elapse++;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            int v;
            cin>>v;
            G[u-1].push_back(--v);
        }
    }
    for(int i=0;i<N;++i) dfs(i);
    for(int i=0;i<N;++i) cout<<i+1<<' '<<D[i].first<<' '<<D[i].second<<endl;
}

C++: #include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


#define INF 1000000000000
int n;
vector<int>d(101);
vector<int>f(101);
vector<vector<int>>g(101,vector<int>(0));
int tim=1;
void dfs(int x){
      if(!d[x]){d[x]=tim;tim++;}
      if(!g[x].size()&& !f[x]){f[x]=tim; tim++;}
  rep(i,g[x].size()){
    if(!d[g[x][i]])dfs(g[x][i]);
    if(i==g[x].size()-1&& !f[x]){f[x]=tim;tim++;}
  }
}
int restart=0;
bool owari(vector<int>l){
  rep(i,n){
    if(l[i+1]==0){return false;}
  }
  return true;
}
signed main() {

   cin>>n;
   rep(i,n){
     int t,m;cin>>t>>m;
     rep(j,m){int k; cin>>k; if(k!=i+1){g[i+1].push_back(k);}}
   }

   while(!owari(d)){
     int restart=0;
     rep(i,n){if(d[i+1]==0){restart=i+1;break;}}
     dfs(restart);
   }
   rep(i,n){
     cout<<i+1<<' '<<d[i+1]<<' '<<f[i+1]<<endl;
   }
}

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

#define start first
#define end second

static const int NOT   = false;
static const int WHITE = 1;
static const int GRAY  = 2;
static const int BLACK = 3;
static const int N	   = 101;

int  n;
int  VisitedInfo[N];
bool Graph[N][N];
pair< int, int > Time[N];

void dfs( int u );
int  nextNode( int u );

int main()
{

	int u, k, v;

	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) Graph[i][j] = NOT;
		VisitedInfo[i] = WHITE;
	}

	scanf( "%d", &n );
	for( int i = 0; i < n; i++ ) {
		
		scanf( "%d %d", &u, &k );
		for( int j = 0; j < k; j++ ) {

			scanf( "%d", &v );
			Graph[u][v] = true;

		}

	}

	dfs( 1 );

	for( int i = 1; i <= n; i++ ) printf( "%d %d %d\n", i, Time[i].start, Time[i].end );

	return 0;

}

void dfs( int u )
{

	int time = 1;
	stack< int > dfsInfo;

	dfsInfo.push( u );
	Time[u].start  = time;
	VisitedInfo[u] = GRAY;

	while( !dfsInfo.empty() ) {

		int ppos = dfsInfo.top();
		int pos  = nextNode( ppos );

		if( pos != 0 ) {
			if( VisitedInfo[pos] == WHITE ) {

				dfsInfo.push( pos );
				Time[pos].start  = ++time;
				VisitedInfo[pos] = GRAY;

			}
		}
		if( pos == 0 && VisitedInfo[ppos] != WHITE ){

			dfsInfo.pop();
			Time[ppos].end	  = ++time;
			VisitedInfo[ppos] = BLACK;

		}

	}

}

int nextNode( int now )
{

	for( int i = 1; i <= n; i++ ) {
		if( Graph[now][i] && VisitedInfo[i] == WHITE ) return i;
	}

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long int llg;

const int INF = 1000001000;
#define REP(var, count) for(int var=0; var<count; var++)

template <typename T>
using reverse_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

vector<int> rin[105];
pair<int, int> res[105];

int bfs(int a, int time) {
	res[a].first = time;
	for ( int r : rin[a] ) {
		if ( res[r].first != -1 ) { continue; }
		time = bfs(r, time + 1);
	}
	res[a].second = time + 1;
	return res[a].second;
}

int main(void) {
	int N;
	cin >> N;
	
	for(int i=1; i<=N; i++) {
		res[i].first = -1;
		res[i].second = -1;
		
		int U, K;
		cin >> U >> K;
		REP(j, K) {
			int x;
			cin >> x;
			rin[U].push_back(x);
		}
	}
	
	bfs(1, 1);
	
	for(int i=1; i<=N; i++) {
		printf("%d %d %d\n", i, res[i].first, res[i].second);
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int n; //頂点数
vector<vector<int> > g;//グラフ
vector<int>d;//到着時刻を記録
vector<int>f;//終了時刻を記録
void dfs(int v,int& i) {
    if(d[v] == 0) {
        i++;
        d[v] = i;//到着時刻を記録
    }    
    
    for(int next_v : g[v]) {
        if(d[next_v]) continue;//訪問済みなら飛ばす
        dfs(next_v,i);//隣接頂点について探索
    }
    if(f[v] == 0) {
        i++;
        f[v] = i;//終了時刻を記録
    }
}
int main() {
    cin >> n;
    //nで初期化
    g.resize(n);
    f.resize(n);
    d.resize(n);
    rep(i,n) {
        int u; //頂点番号
        cin >> u;
        u--;
        int k; //出次数
        cin >> k;
        rep(j,k) {
            int v;//隣接する頂点
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    int count = 0;
    //各頂点からdfs
    for(int i = 0;i<n;i++) {
        dfs(i,count);
    }    
    //各頂点について到着時刻と終了時刻を出力
    for(int i = 0;i<n;i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}