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

#include <queue>

using namespace std;

int a[101][101];

int n=0;

int found[101];

int ended[101];

int aaa(int i, int time);

int main(){

  for(int i=0; i<101; i++)

    for(int j=0; j<101; j++)

      a[i][j]=0;

  int u, k, v;

  cin>>n;

  for(int i=0; i<n; i++){

    cin>>u>>k;

    for(int j=0; j<k; j++){

      cin>>v;

      a[u][v]=1;

    }

  }

  int time=0;

  for(int i=0; i<101; i++){

    found[i]=0;

    ended[i]=0;

  }

  for(int i=1; i<n+1; i++){

    if(found[i]>0)

      continue;

    time++;

    found[i]=time;

    time=aaa(i, time);

    ended[i]=time;

  } 

  for(int i=1; i<n+1; i++)

    cout<<i<<' '<<found[i]<<' '<<ended[i]<<endl;

}

int aaa(int i, int time){

  for(int k=1; k<n+1; k++){

    if(a[i][k]==1&&found[k]==0){

      time++;

      found[k]=time;

      time=aaa(k, time);

      ended[k]=time;

    } 

  }

  time++;

  return time;

}

C++: #include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

#define NODE_NUM (100)

int n;
int current_time = 0;
int M[NODE_NUM][NODE_NUM] = { 0 };
int ans[NODE_NUM][2] = { 0 };
stack<int> S;

void DepthFirstSearch(int node)
{
	int current, next;

	current_time++;

	S.push(node);
	ans[node - 1][0] = current_time;

	while (!S.empty()) {
		current_time++;

		current = S.top();
		next = -1;

		rep(i, n) {
			if (M[current - 1][i] == 1 && ans[i][0] == 0) {
				next = i + 1;
				break;
			}
		}

		if (next == -1) {
			ans[current - 1][1] = current_time;
			S.pop();
		}
		else {
			ans[next - 1][0] = current_time;
			S.push(next);
		}
	}
}

int main()
{
	int u, k, v;
	bool NowSearching = true;

	cin >> n;
	rep(i, n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> v;
			M[u - 1][v - 1] = 1;
		}
	}

	rep(i, n) {
		if (ans[i][0] == 0) DepthFirstSearch(i + 1);
	}

	rep(i, n) {
		cout << i + 1 << ' ' << ans[i][0] << ' ' << ans[i][1] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,a,m,b,s[100],t[100],cnt=1;
vector<int> v[100];
void dfs(int n){
    if(s[n]==0){s[n]=cnt;cnt++;}
    for(auto x:v[n]){
        if(s[x]==0)dfs(x);
    }
    if(t[n]==0){t[n]=cnt;cnt++;}
    return ;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>m;
        for(int j=0;j<m;j++){
            cin>>b;
            if(a==b)continue;
            v[a-1].push_back(b-1);
        }
    }
    for(int i=0;i<n;i++)if(s[i]==0)dfs(i);
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<s[i]<<" "<<t[i]<<endl;
    }
}

C++: class Node(object):
    def __init__(self, V):
        self.V = V
        self.find_time = 0
        self.finish_time = 0
        self.is_finded = False
 
 
n = int(input())
nodes = [0] * 101
for i in range(n):
    data = input().split()
    V = list(map(int, data[2:]))
    V.sort(reverse = True)
    nodes[int(data[0])] = Node(V)
 
find_q = []
find_q.append(1)
cnt = 1
q_size = len(find_q)
while q_size != 0:
    #print(find_q)
    node = nodes[find_q[q_size -1]]
 
    if node.is_finded == False:
        node.find_time = cnt
        cnt += 1
        node.is_finded = True
        if len(node.V) == 0:
            node.finish_time = cnt
            cnt += 1
            find_q.pop()
            q_size = len(find_q)
        else:
            for x in node.V:
                if x in find_q:
                    find_q.remove(x)
                if nodes[x].finish_time == 0: 
                    find_q.append(x)
            q_size = len(find_q)
 
    else:   #node is finded
        node.finish_time = cnt
        cnt += 1
        find_q.pop()
        q_size = len(find_q)
        continue
 
for i in range(1, n+1):
    if not isinstance(nodes[i], int):
        print(i, nodes[i].find_time, nodes[i].finish_time)

C++: #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;
}