Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <queue>

using namespace std;

int d[101];
int f[101];
bool isUsed[101];
int count = 0;

void dfs(vector< vector<int> >& G, int vertex);
void calclation();

int main()
{
	calclation();
	return(0);
}

void dfs(vector< vector<int> >& G, int vertex)
{
	d[vertex] = ++count;
	for (int i = 0; i < G[vertex].size(); ++i)
	{
		if (G[vertex][i] == 1 && isUsed[i] == false)
		{
			isUsed[i] = true;
			dfs(G, i);
		}
	}
	f[vertex] = ++count;
}

void calclation()
{
		int n;
	cin >> n;

	vector< vector<int> > G(n, vector<int>(n));
	for (int i = 0; i < n; ++i)
	{
		int h, k;
		cin >> h >> k;
		--h;
		for (int j = 0; j < k; ++j)
		{
			int v;
			cin >> v;
			--v;
			G[h][v] = 1;
		}
	}
	for (int i = 0; i < 101; ++i)
	{
		isUsed[i] = false;
	}
	for (int i = 0; i < n; ++i)
	{
		if (isUsed[i] == false)
		{
			isUsed[i] = true;
			dfs(G, i);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

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

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    cin >> n;
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        cin >> a >> e;
        for(j = 1; j <= e; j++){
            cin >> b; G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

    for(i = 1; i <= n; i++){
        cout << i << " " << found[i] << " " << comp[i] << endl << endl;
    }
    return 0;
}

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

stack<int> S;
int n, x[10000][10000], a, b, c, d, _time=1;
int y[10000][3];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			x[i][d] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		x[0][i] = 1;
	}
	S.push(0);
	while (!S.empty()) {
		a = S.top();
		for (int i = 1; i <= n; i++) {
			if (x[a][i] == 1 && y[i][0] == 0) {
				y[i][0] = 1;
				y[i][1] = _time;
				S.push(i);
				goto Exit;
			}
		}
		S.pop();
		y[a][2] = _time;
	Exit:;
		_time++;
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << y[i][1] << ' ' << y[i][2] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int ans[100][2],degree,count=1;
int arr[100][100],visible[100];
void dfs(int i)
{
	for(int j=0;j<degree;j++)
	{
		if(arr[i][j]==1 && visible[j]==0)
		{			
			ans[j][0]=count++;
			visible[j]=1;
			dfs(j);
			ans[j][1]=count++;
		}
	}
}
int main()
{
	int number,num;
	cin>>degree;

	for(int i=0;i<100;i++)
	{
		visible[i]=0;
	}	
	for(int i=0;i<degree;i++)
	{
		for(int j=0;j<degree;j++)
		{
			arr[i][j]=0;
		}
	}
	for(int i=0;i<degree;i++)
	{
		cin>>number;
		cin>>number;
		for(int j=0;j<number;j++)
		{
			cin>>num;
			arr[i][num-1]=1;
		}
	}
	for(int i=0;i<degree;i++)
	{
		if(visible[i]==0)
		{
			ans[i][0]=count++;
			visible[i]=1;
			dfs(i);
			ans[i][1]=count++;
		}
	}
	for(int i=0;i<degree;i++)
	{
		cout<<i+1<<" "<<ans[i][0]<<" "<<ans[i][1]<<endl;
	}
}

C++: #include <iostream>
using namespace std;
static const int N = 100;
static const int NONE = 0;
static const int DETECTED = 1;
static const int FINISHED = 2;

int M[N][N];

void dfs(int u, int n, int M[N][N], int status[], int t_detected[], int t_finished[], int &t) {
    status[u] = DETECTED;
    t_detected[u] = ++t;
    for (int v = 0; v < n; v++) {
        if (M[u][v] != 0 && status[v] == NONE) {
            dfs(v, n, M, status, t_detected, t_finished, t);
        }
    }
    status[u] = FINISHED;
    t_finished[u] = ++t;
}

int main() {
    int n, 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;
        }
    }

    int status[n], t_detected[n], t_finished[n];
    for (u = 0; u < n; u++) {
        status[u] = NONE;
        // t_detected[u] = 0;
        // t_finished[u] = 0;
    }
    int t = 0;

    for (u = 0; u < n; u++) {
        if (status[u] == NONE) dfs(u, n, M, status, t_detected, t_finished, t);
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << t_detected[i] << " " << t_finished[i] << endl;
    }

    return 0;
}