Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<cstdio>

class Graph{
    int n;
    int **G;
    int *seen;
    int *time_d;
    int *time_f;
    
    public: Graph(int _n){
        n = _n;
        G = new int*[n+1];
        seen = new int[n+1];
        time_d = new int[n+1];
        time_f = new int[n+1];
        for(int i = 0;i <=n;++i){
            G[i] = new int[n+1];
            time_d[i] = 0;
            time_f[i] = 0;
        }
        for(int i = 0;i <= n;++i){
            for(int j = 0;j <= n;++j){
                G[i][j] = 0;
            }
        }
    }
    
    public: void BuildMatrix(){
        int u,k,v;
        for(int i = 0;i < n;++i){
            scanf("%d %d",&u,&k);
            for(int j = 0;j < k;++j){
                scanf("%d",&v);
                G[u][v] = 1;
            }
        }
    }
    
    public: void PrintMatrix(){
        for(int i = 1;i <= n;++i){
            for(int j = 1;j <n;++j){
                printf("%d ",G[i][j]);
            }
            printf("%d\n",G[i][n]);
        }
    }
    
    public :void DoDFS(){
        int c = 0;
        for(int i = 0;i <= n;++i) seen[i] = 0;
        DFS(1,c);
        for(int i = 1;i <= n;++i){
            if(seen[i] != 1) DFS(i,c);
        }
        for(int i = 1;i <= n;++i){
            printf("%d %d %d\n",i,time_d[i],time_f[i]);
        }
    }
    
    void DFS(int s,int& cnt){
        cnt++;
        seen[s] = true;
        time_d[s] = cnt;
        for(int j = 1;j <= n;++j){
            if(G[s][j] == 1 && seen[j] == 0){
                DFS(j,cnt);
            }
        }
        cnt++;
        time_f[s] = cnt;
    }
    
};

int main(){
    int n;
    scanf("%d",&n);
    Graph G(n);
    G.BuildMatrix();
    G.DoDFS();
}

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;
}