Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

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

using namespace std;

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int N;
int M[MAX][MAX];
int C[MAX];

int d[MAX], f[MAX];
int tt;

void dfs_visit(int u) {
    C[u] = GRAY;
    d[u] = ++tt;
    for (int i = 0; i < N; i++) {
        if (M[u][i] == 1 && C[i] == WHITE) {
            dfs_visit(i);
        }
    }
    C[u] = BLACK;
    f[u] = ++tt;
    
}

void dfs() {
    for (int i = 0; i < N; i++) {
        if (C[i] == WHITE) {
            dfs_visit(i);
        }
    }
    
    for (int i = 0; i < N; i++) {
        printf("%d %d %d\n", i + 1, d[i], f[i]);
    }
}

int main() {
    int u, k;
    
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();

    return 0;
}

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

#define WHITE 0   // not visited yet.
#define GRAY 1    // visited, but not completed.
#define BLACK 2   // search completed.

int G[101][101];        // adjacency list.
int color[101];         // visited/completed sign.
int n;                  // size.
int d[101], f[101], t;  // first visit time/complete time.

void search_loop(int i) 
{
    int next;
    d[i] = ++t;
    color[i] = GRAY;  // first visited.

    for(next = 1; next <= n; next++){
        if(i == next && G[i][i] > 0) break;   // if self-looped, through.
        if(G[i][next] > 0 && color[next] == WHITE){  // if not visited yet, visit.
            search_loop(next);
        }
    }
    f[i] = ++t;
    color[i] = BLACK;  // completed. 

    return;
}

void dfs()
{
    int i;
    for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.
    t = 0;

    for(i = 1; i <= n; i++) if(color[i] == WHITE) search_loop(i);

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

    return ;
}

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

    do{
        cin >> i >> e;
        for(j = 1; j <= e; j++){
            cin >> k;
            G[i][k] = 1;
        }
    }while(i < n);

    dfs();
    return 0;
}

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

using Graph = std::vector<std::vector<uint32_t>>;

uint32_t dfs(const Graph& G, std::vector<std::pair<uint32_t, uint32_t>>& ts,
             uint32_t node, uint32_t t) {
  ts[node].first = t;
  for (auto&& g : G[node]) {
    if (ts[g].first == 0) t = dfs(G, ts, g, t + 1);
  }
  t++;
  ts[node].second = t;
  return t;
}

int main() {
  uint32_t n = 0;
  std::cin >> n;
  Graph G(n + 1);
  for (size_t i = 1; i < n + 1; i++) {
    uint32_t k = 0;
    std::cin >> i >> k;
    if (k > 0) G[i] = std::vector<uint32_t>(k);
    for (auto&& g : G[i]) std::cin >> g;
  }

  uint32_t time = 0;
  std::vector<std::pair<uint32_t, uint32_t>> timestamp(n + 1, {0, 0});
  for (size_t i = 1; i < timestamp.size(); i++) {
    if (timestamp[i].first == 0) time = dfs(G, timestamp, i, time + 1);
  }

  for (size_t i = 1; i < timestamp.size(); i++) {
    std::cout << i << " " << timestamp[i].first << " " << timestamp[i].second
              << std::endl;
  }

  return 0;
}