Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define INF 1000000007
typedef int64_t in;
typedef long long ll;

int n;
int m[105][105] = {};
int color[105] = {};
int d[105] = {};
int f[105] = {};
int u,k;
int v;
int t=0;
int nt[105] = {};

int next(int u){
    REP(v, nt[u], n){
        nt[u] = v + 1;
        if(m[u][v]) return v;
    }
    return -1;
}

void dfs(int u){
    rep(u,n){
        if(color[u] == 0){
            stack<int> S;
            color[u] = 1;
            d[u] = ++t;
            S.push(u);

            while(!S.empty()){
                u = S.top();
                v = next(u);
                if(v != -1){
                    if(color[v] == 0){
                        S.push(v);
                        color[v] = 1;
                        d[v] = ++t;
                    }
                }else{
                    S.pop();
                    color[u] = 2;
                    f[u] = ++t;
                }
                
            }
        }
    }

    rep(i,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(){
    cin >> n;
    
    /*rep(i,n){
        color[i] = 0;
    }*/

    rep(i,n){
        cin >> u >> k;
        for(int i=0; i<k; i++){
            cin >> v;
            m[u-1][v-1] = 1;
        }
    }

    dfs(0);
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
        }
    }
    stack<int> dfs;
    int time = 2;
    dfs.push(1);
    d[1] = 1;
    bool flag = true;
    while(flag) {
        while (!dfs.empty()) {
            int u = dfs.top();
            bool fl = false;
            for (int i = 1; i <= n; i++) {
                if (g[u][i] && d[i] == 0 && u != i) {
                    dfs.push(i);
                    d[i] = time++;
                    fl = true;
                    break;
                }
            }
            if (!fl) {
                dfs.pop();
                f[u] = time++;
            }
        }
        flag = false;
        for(int i =1;i <= n;i++) if(d[i] == 0){flag = true;dfs.push(i);d[i] = time++;}
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}

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

#define MAX 100

#define WHITE 0
#define GRAY 1
#define BLACK 2

int T;
int N;

int M[MAX][MAX];
int D[MAX], F[MAX], C[MAX];

void dfs(int u)
{
    C[u] = GRAY;
    D[u] = ++T;

    for (int i = 0; i < N; i++)
    {
        if(M[u][i] == 1 && C[i] == WHITE)
        {
            dfs(i);
        }        
    }
    C[u] = BLACK;
    F[u] = ++T;
}

int main ()
{
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    T = 0;

    for (int i = 0; i < N; i++)
    {
        if (C[i] == WHITE)
        {
            dfs(i);
        }
    }

    /*
    stack<int> *S = new stack<int>;


    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            if (M[u][i] == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }
*/

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(true){
		while(!back.empty()){
			int r;
			r = next(current);
			if(start_end[current][0] == 0){
				start_end[current][0] = count;
				count++;
			}
			if(r){
				matrix[current][r-1] = false;
				back.push(current);
				current = r - 1;
			}
			else{
				if(start_end[current][1] == 0){
					start_end[current][1] = count;
					count++;
				}
				current = back.top();
				back.pop();
			}
		
		}
		for(int i = 0; i < n; i++){
			if(start_end[i][0] == 0 || start_end[i][1] == 0){
				back.push(i);
				break;
			}
		}
		if(back.empty())
			break;
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}

}