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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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<stack>
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];

//uに隣接するvを番号順に取得
int next(int u){
    for (int v=nt[u]; v<n; v++){
        nt[u]=v+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;//u頂点の終了時刻
        }
    }
}

void dfs(){
    //初期化
    for (int i=0; i<n; i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    
    //未訪問のuを始点として深さ優先探索
    for (int u=0; u<n; u++){
        if(color[u]==WHITE) 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++: #include <iostream>
#include <stack>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int color[MAX],d[MAX],f[MAX];
int n,t;
int N[MAX][MAX];
void dfs(int u){
    color[u] = GRAY;
    d[u] = ++t;
    for(int v=0;v<n;v++){
        if(N[u][v]!=0&&color[v]==WHITE){
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}
void dfs_init(){
    t = 0;
    for(int i=0;i<n;i++){
        color[i] = WHITE;
    }
    for(int i=0;i<n;i++){
        if(color[i]==WHITE)
            dfs(i);
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" " <<f[i]<<endl;
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            N[i][j] = 0;
        }
    }
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int v;
            cin>>v;
            N[i][v-1] = 1;
        }
    }
    dfs_init();
    return 0;
}

C++: #include<iostream>
int main(){

  int n,a;
  std::cin>>n;

  int Adj[100][100],adj[100][100]={0},find[100][2],back[100][100],depth[100]={0},endflag[100]={0},flag;
	int u[n],k[n],kcou=0,timenow=0,v,pred,prev,firstv,backcount[100]={0},flag1=0;
  for(int i=0;i<n;i++){
    std::cin>>u[i];
    std::cin>>k[i];
    for(int j=0;j<k[i];j++){
      std::cin>>Adj[i][j];
    }
  }
	
	/*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    	std::cout<<Adj[i][j]<<" ";
    }
  	std::cout<<"\n";
  }*/
	
	v=0;
	firstv=0;
	while(timenow<n*2){
		flag=0;
		if(find[firstv][0]!=NULL&&find[firstv][1]!=NULL){
			for(int i=0;i<n;i++){
				if(find[i][0]==NULL){
					//std::cout<<i<<"\n";
					firstv=i;
					v=i;
					break;
				}
			}
		}
		
		// std::cout<<"v="<<v+1<<" ";
		//std::cout<<find[v][0]<<" "<<find[v][1];
		// std::cout<<" endflag="<<endflag[v]<<" ";
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			// std::cout<<v+1<<"[0]= '"<<timenow<<"' ";
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(endflag[v]==1){
				if(backcount[v]<=1){
				timenow++;
				find[v][1]=timenow;
				// std::cout<<v+1<<"[1]= '"<<timenow<<"' ";
				}
				flag=2;
			}
			//std::cout<<flag;
		}else{
			backcount[v]--;
			v=back[v][backcount[v]];
			//backcount[v]--;
			flag=3;
			//std::cout<<flag<<" 0";
		}

		if(flag==0){
				pred=depth[v];
				depth[v]++;
				prev=v;
				v=Adj[v][pred]-1;
				back[v][backcount[v]]=prev;
				backcount[v]++;
				//std::cout<<flag<<"\n";
		}else if(flag==1){
			if(endflag[v]==0){
				if(Adj[v][depth[v]]-1!=v){
					while(find[Adj[v][depth[v]]-1][0]!=NULL && k[v]-1!=depth[v]){
						depth[v]++;
					}
					if(find[Adj[v][depth[v]]-1][0]==NULL){
						pred=depth[v];
						depth[v]++;
						prev=v;
						v=Adj[v][pred]-1;
						back[v][backcount[v]]=prev;
						backcount[v]++;
					}else{
						depth[v]++;
					}
				}else{
					pred=depth[v];
					depth[v]++;
				}
			}
		}else if(flag==2){
			backcount[v]--;
			v=back[v][backcount[v]];
			//backcount[v]--;
			//std::cout<<flag<<"\n";
		}
		if(depth[v]>k[v]-1){
			endflag[v]=1;
		}
		// std::cout<<"flag="<<flag<<"\n";
	}
	
	
	
	
  for(int i=0;i<n;i++){
     std::cout<<i+1<<" "<<find[i][0]<<" ";
     std::cout<<find[i][1]<<"\n";
    //std::cout<<"\n";
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
struct id{
    int c[101];
    int d=0;
    int f=0;
    int u=0;
};
int n,t=0;
id a[101];
void time(int e){
    if(a[e].u==0){
        a[e].u++;
        a[e].d=++t;
        for(int i=1;i<=n;i++){
            if(a[e].c[i]==1){
                time(i);
            }
        }
        a[e].f=++t;
    }
}
int main(){
    int x,y,z;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y;
        for(int j=0;j<y;j++){
            cin>>z;
            a[x].c[z]=1;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i].u==0){
            time(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<a[i].d<<" "<<a[i].f<<endl;
    }
    return 0;
}