Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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