Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

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