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<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
bool visited[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    visited[cur]=true;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if((matrix[cur-1][l[cur][i]-1]==1)&&(visited[i]==false))
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
    
    
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        visited[i]=false;
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    for(int i=1;i<n+1;i++)
    {
        if(visited[i]==false)
            dfs(i);
    }
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

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

using std::cin;
using std::cout;

struct vertex {
    int vv;
    int ww;
};

//enum class VColor {White, Gray, Black};
typedef enum {White, Gray, Black} VColor;

void
dfsearch(std::vector<vertex> *gar, int gsz, int uu,
         std::vector<VColor> &color,
         std::vector<int> &dd, std::vector<int> &ff, std::vector<int> &prev,
         int &cnt)
{
    color[uu] = Gray;
    dd[uu] = ++cnt;
    //cout << uu << " " << cnt << std::endl;
    std::vector<vertex>::iterator it = gar[uu].begin();
    for (; it != gar[uu].end(); it++) {
        int     vv = (*it).vv;
        if (color[vv] == White) {
            prev[vv] = uu;
            dfsearch(gar, gsz, vv, color, dd, ff, prev, cnt);
        }
    }
    
    color[uu] = Black;
    ff[uu] = ++cnt;
    return;
}

int
main()
{
    int vn;
    std::vector<vertex> gar[100 + 1];

    cin >> vn;
    for (int idx = 0; idx < vn; idx++) {
        int uu;
        int kk;
        int vv;

        cin >> uu >> kk;
        for (int ik = 0; ik < kk; ik++) {
            cin >> vv;
            gar[uu].push_back({vv, 1});
        }
    }

#if 0
    for (int uu = 1; uu <= vn; uu++) {
        std::vector<vertex>::iterator it = gar[uu].begin();
#if 0
        for (; it != gar[uu].end(); it++) {
            printf("v = %d w = %d\n", (*it).vv, (*it).ww);
        }
#else
        for (int vv = 1; vv <= vn; vv++) {
            if (vv != 1) cout << ' ';
            if ((it != gar[uu].end()) && ((*it).vv == vv)) {
                cout << '1';
                it++;
            } else {
                cout << '0';
            }
        }
        cout << std::endl;
#endif
    }
#endif

    std::vector<VColor> color;
    std::vector<int> dd;
    std::vector<int> ff;
    std::vector<int> prev;
    int counter;

    color.assign(vn + 1, White);
    dd.assign(vn + 1, 0);
    ff.assign(vn + 1, 0);
    prev.assign(vn + 1, 0);

    counter = 0;
    dfsearch(gar, vn, 1, color, dd, ff, prev, counter);
    std::vector<VColor>::iterator cit = color.begin();
    for (cit++; cit != color.end(); cit++) {
        if (*cit == White) {
            dfsearch(gar, vn, std::distance(color.begin(), cit), color,
                     dd, ff, prev, counter);
        }
    }

    for (int uu = 1; uu <= vn; uu++) {
        cout << uu << " " << dd[uu] << " " << ff[uu] << std::endl;
    }
}

C++: #include"bits/stdc++.h"
using namespace std;

struct Node {
	int in, out;
	bool flag = false;
	vector<int> v;
};

int dfs(vector<Node>& u, int id, int d)
{
	if (u[id].flag) return d - 1;

	int a;
	u[id].in = d;
	u[id].flag = true;
	for (int i = 0; i < u[id].v.size(); i++)
	{
		d = dfs(u, u[id].v[i], d + 1);

	}
	u[id].out = d + 1;
	return d + 1;
}

int main(void)
{
	int N, id, k, x;
	Node z;
	cin >> N;
	vector<Node> u(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> id >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x;
			u[id].v.push_back(x);
		}
	}

	int d = 0;
	for(int i = 1; i <= N; i++) d = dfs(u, i, d + 1);

	for (int i = 1; i <= N; i++) cout << i  << " " << u[i].in << " " <<  u[i].out << endl;

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

vector<int> graph[100];
int d[100], f[100];
int visited = 0;

void dfs(int id){
    d[id] = visited++;
    for(int i = 0; i < graph[id].size(); i++)
	{
        if(graph[id][i] != id && !d[graph[id][i]] && !f[graph[id][i]])
		{
			dfs(graph[id][i]);
		}
    }
    f[id] = visited++;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
	{
        int u, k;
        cin >> u >> k;
        for(int j = 0;j < k;j++)
		{
            int v;
            cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    dfs(0);
    for(int i = 0;i < n;i++)
	{
        if(!f[i]) 
		{
			dfs(i);
		}
    }
    for(int i = 0;i < n;i++)
	{
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}