Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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];
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <stack>
#include <map>

using namespace std;

template<typename ISTREAM>
void readGraphListAsMatrix(const size_t n, ISTREAM& cin, vector< vector<int> >& graphMatrix) {
	graphMatrix = vector< vector<int> >(n, vector<int>(n, 0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u >> k;
		for (size_t j = 0; j != k; ++j) {
			size_t v;
			cin >> v;
			graphMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
}

void printMatrix(const vector< vector<int> >& grapthMatrix) {
	const size_t n = grapthMatrix.size();
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}
}


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > graphMatrix;
	readGraphListAsMatrix(n, cin, graphMatrix);
	stack<int> visitedNodeIDs;
	visitedNodeIDs.push(1);
	int time = 0;
	vector<pair<int, int>> timeStamp(n,make_pair(0,0));//pair<初回訪問時刻, 完了時刻>
	timeStamp.at(0).first = 1;
	while (!visitedNodeIDs.empty()) {
		++time;
		const int nodeID = visitedNodeIDs.top();
		vector<int>& neighbourNodeList = graphMatrix.at(nodeID - 1);
		vector<int>::iterator result = find(neighbourNodeList.begin(), neighbourNodeList.end(), 1);
		if (result != neighbourNodeList.end()) {
			const int nextVisitID = distance(neighbourNodeList.begin(), result) + 1;
			timeStamp.at(nextVisitID - 1).first = time + 1;
			*result = 0;
			visitedNodeIDs.push(nextVisitID);
		}
		else {
			//隣接リストに検索対象なし
			timeStamp.at(nodeID - 1).second = time+1;
			visitedNodeIDs.pop();
		}
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << timeStamp.at(i).first << " " << timeStamp.at(i).second << endl;
	}
}

int main()
{

	execute(cin);


	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void dfs(int node, std::vector<std::vector<int>>& v, int& time, std::vector<std::vector<int>>& log) {
    log[node].push_back(++time);
    for (int i=0; i<v[node].size(); i++) {
        if (node != v[node][i] and log[v[node][i]].size() == 0) {
            dfs(v[node][i], v, time, log);
        }
    }
    log[node].push_back(++time);
} 

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vi, time=0;
    std::cin >> n;
    std::vector<std::vector<int>> v(n+1), log(n+1);
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vi;
            v[u].push_back(vi);
        }
    }
    for (int i=1; i<=n; i++) {
        if (log[i].size() == 0) {
            dfs(i, v, time, log);
        }
    }
    for (int i=1; i<=n; i++) {
        std::cout << i << " " << log[i][0] << " " << log[i][1] << "\n";
    }

    return 0;
}

C++: #define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

vector<int> G[100+1];
vector<int> d(100+1,-1);
vector<int> f(100+1,-1);
int timer= 1;

void dfs(int x){

    if(d[x]!=-1)
        return;
    d[x] = timer;
    timer++;
    for (int i = 0; i < G[x].size(); ++i) {
        dfs(G[x][i]);
    }
    f[x] = timer;
    timer++;
}

int main(void) {

    int n; cin>>n;
    for (int i = 1; i <= n; ++i) {
        int u,k; cin>>u>>k;
        for (int j = 1; j <= k; ++j) {
            int v; cin>>v;
            G[u].push_back(v);
        }
    }

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

    for (int i = 1; i <= n; ++i) {
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }

    return 0;
}