Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

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

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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];
		
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			std::cout<<" '"<<timenow<<"' \n";
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(v==7){
				//std::cout<<endflag[v];
				//std::cout<<backcount[v];
			}
			if(endflag[v]==1){
				if(backcount[v]<=1){
				timenow++;
				find[v][1]=timenow;
				std::cout<<" '"<<timenow<<"' \n";
				}
				flag=2;
			}
			//std::cout<<flag<<" 2";
		}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){
				flag1=0;
				if(Adj[v][depth[v]]-1!=v){
					//std::cout<<"flag1="<<flag1<<"\n";
					if(find[Adj[v][pred]-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<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

C++: #include<iostream>

using namespace std;
const int N = 100;
const int UNVISITED = 0;
const int VISITING = 1;
const int VISITED = 2;
int A[N][N];
int state[N], d[N], f[N];
int n, tt;
int nt[N];

void dfs_visit(int u) {
   
	state[u] = VISITED;
	d[u] = ++tt;

	for( int v =0; v < n; v++ ) {
		if( A[u][v] && state[v] == UNVISITED ) dfs_visit(v);
	}
	f[u] = ++tt;
}
void dfs() {
   for( int i = 0; i < n; i++) {
   	 state[i]=UNVISITED;
   }
   tt = 0;

   for( int u = 0; u < n; u++ ) {
   		if( state[u] == UNVISITED ) 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++ ) A[i][j] = 0;
	}
	
	for ( int i = 0; i < n; i++ ) {
		cin >> u >> k;
		u--;
		while( k-- ) {
			cin >> v;
			A[u][ v - 1] = 1;
		}
	}
	dfs();

	return 0;
}

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 dfa_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;

    //以未访问的u为起点进行深度搜索优先搜索
    for(int u=0; u<n; u++){
        if(color[u] == WHITE) dfa_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;
}