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 <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
static const int N=100;
static const int WHITE =0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[N][N];//グラフの隣接行列
int color[N],d[N],f[N],tt;//状態
int nt[N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=1;
        if(M[u][v])return v;
    }
    return -1;
}


void dfs_visit(int r){
    
    for(int i=0;i<n;i++)nt[i]=0;
    
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
    
    
}

void dfs(){
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    
    for(int u=0;u<n;u++){
        if(color[u]==WHITE){
            cout<<"a"<<endl;
            dfs_visit(u);
        }
    }
        for(int i=0;i<n;i++){
            cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
        }
}






int main(){

    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=0;
        }
    }
    
    
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    
    
    
    dfs();
    
    
    
    
    

return 0;
}

C++: /*d[n]で最初に発見した時刻を出していき、
f[n]で戻りながら完了時刻をいれていく書き方*/
#include <iostream>
using namespace std;

int r[101][101];
int d[101], f[101], num, visit[101], p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}

C++: #include<iostream>
#include<vector>

using namespace std;

int N;
vector<vector<int>> tree;
vector<pair<int,int>> times;

void stamp(int ind, int &time){
	//cout << ind << "," << time << endl;
	if(times[ind].first == 0) times[ind].first = time++;
	else return;
	if(tree[ind].size() == 0){
		times[ind].second = time++;
		//cout<<"break! " << ind << endl;
		return;
	}
	for(int i=0;i<tree[ind].size();i++){
		//cout << tree[ind][i] << endl;
		stamp(tree[ind][i],time);
	}
	//cout << ind << ":" << time << endl;
	times[ind].second = time++;
	if(ind == 1){
		for(int i=2;i<=N;i++){
			stamp(i,time);
		}
	}
}

int main(){
	cin >> N;
	tree = vector<vector<int>>(N+1);
	times = vector<pair<int,int>>(N+1,make_pair(0,0));

	for(int i=1;i<N+1;i++){
		int ind, branch;
		cin >> ind >> branch;
		vector<int> tmp(branch);
		for(int j=0;j<branch;j++){
			int in;
			cin >> in;
			tmp[j] =  in;
		}
		tree[ind] = tmp;
	}

	int time = 1;
	stamp(1,time);

	int i = 1;
	for(auto st:times){
		if(i<=N)
			cout << i << " " << times[i].first << " " << times[i].second << endl;
		i++;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define WHITE 0
#define GLAY 1
#define BLACK 2

// 頂点の個数
int n;
// 隣接行列
vector<vector<int> > M(100, vector<int>(100, 0));
// 頂点の状態を格納する配列
vector<int> color(100, WHITE);
// 発見時刻を格納する配列
vector<int> d(100);
// 完了時刻を格納する配列
vector<int> f(100);
// 時刻
int tt = 0;

// 再帰的にu(WHITEと仮定)をスタートして探索
void dfs_visit(int u)
{
  // uの状態を訪問済みにする
  color.at(u) = GLAY;
  // uの発見時刻を記録
  d.at(u) = ++tt;
  // uの隣接頂点(小さい順に)探索
  for (int v = 0; v < n; v++)
  {
    if (M.at(u).at(v) == 0)
    {
      // vがuの隣接頂点でないとき
      // このループをスキップ
      continue;
    }
    if (color.at(v) == WHITE)
    {
      // vがuの隣接頂点であり、かつ未発見のとき
      // vをスタートとして探索
      dfs_visit(v);
    }
  }
  // uの隣接頂点の状態が全て完了になっているのでuの状態も完了にする
  color.at(u) = BLACK;
  // uの完了時刻を記録
  f.at(u) = ++tt;
}

// 全ての頂点を探索
void dfs()
{
  for (int i = 0; i < n; i++)
  {
    if (color.at(i) == WHITE)
    {
      dfs_visit(i);
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++)
    {
      int v;
      cin >> v;
      v--;
      M.at(u).at(v) = 1;
    }
  }

  dfs();

  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << d.at(i) << " " << f.at(i) << endl;
  }
}

C++: #include <stdio.h>

#define N 101

int color[N];
int n, G[N][N],f[N],d[N],time;

void visit(int);

int main(){
  int i,j,v,vnext,k;
 
  scanf("%d",&n);

  for(i=0;i<n;i++){
    color[i] = 0;
    for(j=0;j<n;j++) {
      G[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&v,&k);
    for(j=0; j<k; j++){
      scanf("%d",&vnext);
      G[v-1][vnext-1] = 1; 
    }
  }

  for(i=0; i<n; i++){
    if(color[i]==0) visit(i);
  }

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

void visit(int u){

  int i; 
  color[u]=1;
  d[u]= ++time;
  for(i=0; i<n; i++){
    if(G[u][i] == 1){
      if(color[i] == 0)visit(i);
    }
  }

  color[u]= 2;
  f[u]=++time;
}